Reading a subvalue from an XML tag
I'm reading a XML file and parsing it using Ob开发者_如何学Cj-C and cocoa. I am reading the values using the following line (to read the <DocOwner>
tag):
NSArray* DocownerArray = [root nodesForXPath:@"//DocOwner" error:nil];
for(NSXMLElement* xmlElement in DocownerArray)
[DocOwner addObject:[xmlElement stringValue]];
but I ran into a problem, in cases where I have the following:
<Discover id="1234">SomeValue</Discover>
using the previous method will return SomeValue
but no the id=1234
. How can I parse that part?
This is done on XCode 4 for Mac OS X.
Thank youHave you tried NSXMLElement's attributeForName method like
[DocOwner addObject:[[xmlElement attributeForName:@"id"] stringValue]];
and get the stringValue from the returning NSXMLNode?
精彩评论