java - Android Xml 检查 web 服务是否返回 true 或 false

标签 java android xml ios asmx

我正在努力确定流媒体是否直播。我有一个执行此操作的预先存在的文件 ( 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/

相关文章:

java - 符合给定标准的 Scala/Java ORM

java - 如何从 Multimap 的字符串表示中删除第一个和最后一个字符?

android - Unity Android 应用程序上的 Facebook API,登录时说它是 "cancelled by the Player"?

javascript - 递归地将嵌套的xml转换为嵌套的html

java - Android 默认按钮颜色

java - 如何在 Eclipse 中导入 Java 库?

Java 监控 GitHub 存储库

android - 如何使用 New Folder Picker API 将 SD 卡中的图像显示到 ListView?

android - 如何从 res/raw 文件夹打开 PDF 文件?

PHP foreach 没有插入