我正在努力确定流是否有效。我有一个预先存在的文件(http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime)。这是流不活动时返回的内容:
<boolean xmlns="http://tempuri.org/">false</boolean>
当流处于活动状态时,它会返回:
<boolean xmlns="http://tempuri.org/">true</boolean>
我需要帮助创建一个xml阅读器来检查webservice是返回true还是false。谢谢你的帮助。
我最近在iOS上做了同样的事情,这就是我检查XML的方式。
NSError * error = nil;
NSString * responseString = [NSString stringWithContentsOfURL:[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.
}
有没有办法在Android中做类似的事情?
答案 0 :(得分:3)
你必须解析你的xml。解析xml后,您可以获得布尔值true或flase。之后,您可以根据您的使用情况在应用程序中使用该值。
解析android XML PULL解析器中的XML是最好的方法。使用它你可以解析你的xml。
使用以下链接获取更多信息
http://www.ibm.com/developerworks/opensource/library/x-android/
答案 1 :(得分:0)
您似乎正在尝试解析xml。如果是这种情况,你可以使用dom解析器。
这是一个关于它的simepl教程 http://www.androidpeople.com/android-xml-parsing-tutorial-%E2%80%93-using-domparser
答案 2 :(得分:0)
Android设备上提供javax.xml.*
个包。
使用google查找符合您需求的JAVA示例的XML解析。