Parsing XML with TouchXML
Hi guys,
I am trying to parse some xml and save it in a dictionary for ease of use in my code.
The xml has this form:
<root>
<element>
<field1>Some text</field1>
<field2>Some text</field2>
...
</element>
<element>
<field1>Some text</field1>
<field2>Some text</field2>
...
</element>
...
</root>
Right now (I think) I am parsing it but the resulting array has a lot of 'dirt' in it.
Every parsed element il logged like this:
2008-09-14 12:54:25.238 Search 1.0[1708:4203] base
2008-09-14 12:54:25.239 Search 1.0[1708:4203] base
<CXMLElement 0x493ee0 [0x48d990] element <element>
<field1>Some text</field1>
<field2>Some text</field2>
...
</element>>
The code is:
NSError *theError = NULL;
NSString *theXML = [[[NSString alloc] initWithContentsOfURL:[self targetURL]] autorelease];
CXMLDocument *theXMLDocument = [[[CXMLDocument alloc] initWithXMLString:theXML options:0 error:&theError] autorelease];
NSArray *theNodes = NULL;
theNodes = [theXMLDocument nodesForXPath:@"//root" error:&theError];
for (CXMLElement *theElement in theNodes)
{
theNodes = [theElement nodesForXPath:@"./element" error:NULL];
NSLog(@"%@", theNodes);
}
// Write the nodes in an array...
// ...
Is there a working example that I can adapt to that structure of xml?
Also, How do I create a dictionary with the Info.plist style from the Array I am parsing?
Cheers
|