简体   繁体   English

Android Xml检查Web服务是否返回true或false

[英]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 ). 我有一个预先存在的文件可以做到这一点( 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. 我需要创建XML阅读器的帮助,以检查Web服务是否返回true或false。 Thank you for your help. 谢谢您的帮助。

I recently did the same thing on iOS and this is how I checked the XML. 我最近在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.
   } 

Is there a way to do something similar in Android? 有没有办法在Android中做类似的事情?

You have to parse your xml. 您必须解析您的xml。 After parsing your xml you can get Boolean value true or flase. 解析xml之后,您可以获取布尔值true或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. 在Android XML PULL解析器中解析XML是最好的方法。 Using that you can parse your xml. 使用它,您可以解析您的xml。

Use below link for further information 使用下面的链接获取更多信息

http://www.ibm.com/developerworks/opensource/library/x-android/ http://www.ibm.com/developerworks/opensource/library/x-android/

It seems you are trying to parse xml. 看来您正在尝试解析xml。 if thats the case you can use the dom parser. 如果是这样,您可以使用dom解析器。

This is a simepl tutorial on it http://www.androidpeople.com/android-xml-parsing-tutorial-%E2%80%93-using-domparser 这是关于它的simepl教程http://www.androidpeople.com/android-xml-parsing-tutorial-%E2%80%93-using-domparser

The javax.xml.* packages are available on android devices. javax.xml.*包在android设备上可用。

Use google to find a XML parsing with JAVA example that suits your needs. 使用google查找适合您需求的JAVA示例XML解析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM