[英]Creating Xpath Query Dynamically using Touchxml and xcode
I'm new to touchxml and xpath and i just want to know if is there any way to get an attribute of a node dynamically? 我是touchxml和xpath的新手,我只是想知道是否有任何方法可以动态获取节点的属性? I have this xml
我有这个XML
<?xml version="1.0" encoding="UTF-8"?>
<countries>
<country id="Philippines">
<countryname>Philippines</countryname>
<subsidiaries>
<subsidiary>
<name>Sartorius Philippines Inc.</name>
<address>Unit 20-A The World Centre Building, 330 Senator Gil Puyat Avenue Makati 1209 City Philippines, Philippines</address>
<phone>+63.2.8640.929</phone>
<fax>+63.28640.932</fax>
<email>enquiry.philippines@sartorius.com</email>
<website>http://www.sartorius-mechatronics.com.ph</website>
</subsidiary>
</subsidiaries>
</country>
<country id="Denmark">
<countryname>Denmark</countryname>
<subsidiaries>
<subsidiary>
<name>Sartorius Stedim Nordic A|S</name>
<address>stedim Hoerskaetten 6d 2630 Taastrup, Denmark</address>
<phone>+45.7023.4400</phone>
<fax>+45.4630.4030</fax>
<email>ne.customersupport@sartorius.com</email>
<website></website>
</subsidiary>
<subsidiary>
<name>Sartorius Nordic A|S</name>
<address>Hoerskaetten 6D 2630 Taastrup, Denmark</address>
<phone>+45.7023.4400</phone>
<fax>+45.4630.4030</fax>
<email>ne.customersupport@sartorius.com</email>
<website></website>
</subsidiary>
</subsidiaries>
</country>
</countries>`
I have a table view that shows all the country name and what I would like to happen is when I click the word denmark it will show the with an attribute of id="denmark" 我有一个显示所有国家名称的表格视图,当我单击单词denmark时,它将显示带有id =“ denmark”属性的表格
I have this xpath query as for now: 我现在有这个xpath查询:
resultNodes = [rssParser2 nodesForXPath:@"/countries/country[@id]/subsidiaries/subsidiary" error:nil];
I'm not 100% sure of the best way to concatenate strings in Objective-C, but the idea is, assuming you have a variable countryId
with the id you're looking for, you would do something like this: 我不确定在Objective-C中串联字符串的最佳方法,但是我的想法是,假设您有一个具有所需ID的
countryId
变量,则可以执行以下操作:
NSString *xpath =
[NSString stringWithFormat:@"%@/%@/%@",
@"/countries/country[@id = '", countryId, @"']/subsidiaries/subsidiary"];
resultNodes = [rssParser2 nodesForXPath:xpath error:nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.