2016-05-09 58 views
0

嗨我正在與下面的XML是我的xml從服務器。如何檢查xml標籤字符串?

<message xmlns="jabber:client" to="[email protected]" id="A2EFL-1435" from="[email protected]"><x xmlns="jabber:x:event"><composing/><id>A2EFL-1434</id></x></message> 

現在我需要檢查是否有composing元素或XML not.And我沒有使用任何XML代表。有沒有使用委託方法用於XML

NSXMLElement *events = [message elementForName:@"x"]; 
    NSString *eventString=[[message elementForName:@"x"] stringValue]; 
    if (![eventString isEqualToString:@""]) { 
     NSString *composingString=[[events elementForName:@"composing"] stringValue]; 
     if ([composingString isEqualToString:@""]||[composingString isEqualToString:@"nil"]) {} 

任何可能性,但我需要檢查XML標籤不珍惜

+0

但如何檢查標籤等於「作曲」字符串我對每個XML名稱不同 – Bittoo

+0

是正是我對每個XML性反應的不同的字符串,我需要檢查字符串 – Bittoo

+0

如何將'NSXMLElement轉換'到'NSString'。 – Bittoo

回答

0

你可以只是字符串操作做到這一點。檢查這一點。

NSRange rangeValue = [xmlString rangeOfString:@"<composing>" OR @"<composing/>" OR options:NSCaseInsensitiveSearch]; 

if (rangeValue.length > 0){ 

NSLog(@"Tag is present"); 

} 

else { 

NSLog(@"Tag is not present"); 

} 
+0

'NSXMLElement * events = [message elementForName:@「x」]; NSString * xmlString =(NSString *)events; NSRange rangeValue = [xmlString rangeOfString:@「」options:NSCaseInsensitiveSearch];如果(rangeValue.length> 0){NSLog(@「composing Tag is present」); } ' – Bittoo

+0

當我使用上面的代碼時,它得到錯誤,像未識別的 – Bittoo

+0

知道它感謝它的工作正常。但是他們的任何其他方式來檢查XML元素。 – Bittoo