开发者

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 you


Have you tried NSXMLElement's attributeForName method like

[DocOwner addObject:[[xmlElement attributeForName:@"id"] stringValue]];

and get the stringValue from the returning NSXMLNode?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜