How to check the XML tag string?

106 Views Asked by At

Hi I am working with the xml below is my xml from server.

 <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>

Now i need to check that whether xml having composing element or not.And I am not using any xml delegates. Is there any possibility with out using delegate methods for 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"]) {}

But i need to check that xml tag not value

1

There are 1 best solutions below

5
Apurv On

You can just do it with string operations. Check for this.

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

if (rangeValue.length > 0){

NSLog(@"Tag is present");

} 

else {

NSLog(@"Tag is not present");

}