简体   繁体   English

使用TouchXML如何计算以特定文本开头的标签

[英]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 . 您可以使用hasPrefixrangeOfString来检查是否检查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.

相关问题 如何使用touchxml从WSDL文件获取数据 - How to get the data from WSDL file using touchxml TouchXML(Sudzc)并正确使用此数据 - TouchXML (Sudzc) and using this data properly 我有XML跟随如何使用touchXML解析,我想获得像26400174350这样的数据 <p231:proNum> 26400174350 </p231:proNum> - I have XML like follow how do I parse using touchXML, i want to get data like 26400174350 for <p231:proNum>26400174350</p231:proNum> 如何快速获取多维数组中特定项目的计数 - How can I get the count of specific item in multidimensional array swift 如何计算包含特定艺术家的文件? - How can I to count files are which contains a specific artist? 如何在Swift中的同一UILabel上淡入和淡出不同文本? - how can I fade in and out different texts on the same UILabel in Swift? 如何使用文本框和按钮将文本添加到每个单元格中? - How do I add texts into each cell using textfield and button? 使用Touchxml和xcode动态创建Xpath查询 - Creating Xpath Query Dynamically using Touchxml and xcode 使用TouchXML解析XML时发生内存泄漏 - Memory leak while parsing XML using TouchXML 如何在Swift 3的滚动视图中为带有标签的标签设置不同的文本? - how to set different texts to labels with tags in a scrollview in swift 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM