Using TouchXML how can I count tags that starts with specific texts

58 Views Asked by At

Suppose I have an XML file that has tags Reg0, Reg1, Reg2. . . The "Reg" prefix is fixed.

How can I count the number of tags that starts with Reg text using TouchXML?

I can search for Reg text in my whole document, but may be this is not the right procedure.

1

There are 1 best solutions below

1
nsgulliver On

You can check with the if check the current element in the xml document using hasPrefix or using rangeOfString. I would recommend you to use NSXMLParser which is built in iOS. Using NSXMLParser you could check the elementName when parsing the XML document, you could check for the string what you are looking for

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if([elementName hasPrefix:@"Reg"])
        regCount++;
}

or you can use rangeOfString also for elementName

if ([elementName rangeOfString:@"Reg"].location!=NSNotFound)
        regCount++;