2011-09-08 60 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解析。

相關問題