开发者

How to access the value of an attribute from xml using Lib XML parsing in objective-c?

开发者 https://www.devze.com 2023-03-25 02:46 出处:网络
I have chosen the lib xml technique to parse the data from xml parser. But I don\'t know how to extract开发者_开发技巧 the attribute value of a node in xml parser.

I have chosen the lib xml technique to parse the data from xml parser. But I don't know how to extract开发者_开发技巧 the attribute value of a node in xml parser.

Please suggest any solution.


If you are just after a value and you are not walking through the XML tree then you need to learn about XPaths for it I have the XML doc

<a>
 <b>
  <c att="foo"/>
 </b>
 <b>
  <c att="bar"/>
 </b>
</a>

then you path to get the value of bar would be something like this (I haven't done any path for a little while so this may not be exactly right.

/a/b[2]/c/@att/text()

libxml2 has function for dealing with paths, just make sure when google for information of xpaths you specify xpath v1 since libxml2 does not support xpath2.

0

精彩评论

暂无评论...
验证码 换一张
取 消