我正在努力确定流媒体是否直播。我有一个执行此操作的预先存在的文件 ( http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime )。这是流不活动时返回的内容:
<boolean xmlns="http://tempuri.org/">false</boolean>
当流处于 Activity 状态时,它返回:
<boolean xmlns="http://tempuri.org/">true</boolean>
我需要帮助创建一个 xml 阅读器来检查 web 服务是否返回 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 中做类似的事情?
最佳答案
您必须解析您的 xml。解析您的 xml 后,您可以获得 boolean 值 true 或 flase。之后,您可以根据需要在应用程序中使用该值。
对于在 android XML PULL 解析器中解析 XML 是最好的方法。使用它您可以解析您的 xml。
使用下面的链接获取更多信息
http://www.ibm.com/developerworks/opensource/library/x-android/
关于java - Android Xml 检查 web 服务是否返回 true 或 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7348581/