Android Xml check if a webservice returns true or false
I am working on determining if a stream is live or not. I have a preexisiting file that does that (http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime). This is what it returns when the stream is inactive:
<boolean xmlns="http://tempuri.org/">false</boolean>
When the stream is active it returns this:
<boolean xmlns="http://tempuri.org/">true</boolean>
I need help creating a xml reader to check if the webservice returns true or false. Thank you for your help.
I recently did the same thing on iOS and this is how I checked the XML.
NSError * error = nil;
NSString * responseString = [NSString 开发者_如何学CstringWithContentsOfURL:[NSURL URLWithString:@"http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime"] encoding:NSUTF8StringEncoding error:&error];
NSRange range = [responseString rangeOfString : @"true"];
if (range.location != NSNotFound) {
NSLog(@"%@", responseString);
/// Handle active content.
hiddenVideo.hidden = FALSE;
hiddenAudio.hidden = FALSE;
noService.hidden = TRUE;
}
else {
NSLog(@"%@", responseString);
// Inform user that the content is unavailable
hiddenVideo.hidden = TRUE;
hiddenAudio.hidden = TRUE;
noService.hidden = FALSE;
// Inform user that the content is unavailable
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Live Service"
message: @"There is no service going on at this time"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
HasShownAlert = TRUE; //let the other event know that the alert has already been shown.
}
Is there a way to do something similar in Android?
You have to parse your xml. After parsing your xml you can get Boolean value true or flase. After that you can use that value in application as per your use.
For parse the XML in android XML PULL parser is best way. Using that you can parse your xml.
Use below link for further information
http://www.ibm.com/developerworks/opensource/library/x-android/
It seems you are trying to parse xml. if thats the case you can use the dom parser.
This is a simepl tutorial on it http://www.androidpeople.com/android-xml-parsing-tutorial-%E2%80%93-using-domparser
The javax.xml.*
packages are available on android devices.
Use google to find a XML parsing with JAVA example that suits your needs.
精彩评论