0

嗨,我正在使用下面的 xml 是我来自服务器的 xml。

 <message xmlns="jabber:client" to="91957@ip-148" id="A2EFL-1435" from="9176@ip-148"><x xmlns="jabber:x:event"><composing/><id>A2EFL-1434</id></x></message>

现在我需要检查 xml 是否有composing元素。而且我没有使用任何 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 标签不是值

4

1 回答 1

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");

}
于 2016-05-09T06:22:51.107 回答