[英]Using TouchXML how can I count tags that starts with specific texts
Suppose I have an XML file that has tags Reg0, Reg1, Reg2. 假设我有一个XML文件,其中包含标签Reg0,Reg1,Reg2。 .
。 .
。 The "Reg" prefix is fixed.
“ Reg”前缀是固定的。
How can I count the number of tags that starts with Reg text using TouchXML ? 如何使用TouchXML计算以Reg文本开头的标签数?
I can search for Reg text in my whole document, but may be this is not the right procedure. 我可以在整个文档中搜索Reg文本,但是可能这不是正确的过程。
You can check with the if check the current element in the xml document using hasPrefix
or using rangeOfString
. 您可以使用
hasPrefix
或rangeOfString
来检查是否检查xml文档中的当前元素。 I would recommend you to use NSXMLParser
which is built in iOS. 我建议您使用iOS内置的
NSXMLParser
。 Using NSXMLParser
you could check the elementName
when parsing the XML document, you could check for the string what you are looking for 使用
NSXMLParser
您可以在解析XML文档时检查elementName
,还可以检查所需的字符串
- (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
或者您也可以将
rangeOfString
用作elementName
if ([elementName rangeOfString:@"Reg"].location!=NSNotFound)
regCount++;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.