This is my XML
<MyXML ID="tester" Server="example.com">
<CONF>
<MYAPP LOCN="/Application/data/" DATADIR="/tmp/data">
..
</CONF>
</MyXML>
This is the Code i’m using
NSString *xmlFilePath =@"/Applications/conf/MyConf.xml";
NSLog(@"%@",xmlFilePath);
NSData *xmlData = [NSData dataWithContentsOfFile:xmlFilePath];
NSString *xPathQuery =@"/MyXML";
NSArray *xmlArray = PerformXMLXPathQuery(xmlData,xPathQuery);
It gives me the full XML as NSArray. How to traverse through this NSArray or, how to use XPath to get exactly the Nodes and attributes.
I’ve used
NSString *xPathQuery =@"/MyXML[@ID]";
but it doesn’t returns the attribute ID, it just returns null.
I think it would be best to traverse through the NSArray, but how to do that(I’m a newbie to Objective C and when i looked for traversing through the NSArray returned by ,i’ve just got examples for HTML NSArray only)
Take a look at
libxml2wrapper and using libxml2 for XML parsing and XPath queries in Cocoa article.