2011-09-08 63 views
1

我正在确定一个流是否存在或不存在。我有一个预先存档的文件(http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime)。这是当流处于非活动状态它返回什么:Android Xml检查webservice是否返回true或false

<boolean xmlns="http://tempuri.org/">false</boolean>

当流有效时,它返回此:

<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中做类似的事情?

+0

能否请您详细阐述了。我不明白你真的想要什么? –

+0

我需要帮助创建一个XML读取器来检查Web服务是否返回true或false。 –

回答

3

你必须解析你的xml。解析你的xml后,你可以得到布尔值true或flase。之后,您可以根据您的使用情况在应用程序中使用该值。

解析XML XML中的XML PULL解析器是最好的方法。使用它你可以解析你的xml。

使用下面的链接了解更多信息

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

0

一个simepl教程javax.xml.*包可在Android设备上。

使用google查找适合您需求的JAVA示例的XML解析。