Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-14-2008, 05:58 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 8
avirzi is on a distinguished road
Post 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
avirzi is offline   Reply With Quote
Reply

Bookmarks

Tags
nsdictionary, plist, touchxml, xml, xml parsing

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 336
12 members and 324 guests
2Apps1Day, akacaj, Domele, GraffitiCircus, michelle, NetGuru, NSString, Paul Slocum, SLIC, Sloshmonster, soohyun, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,650
Threads: 94,114
Posts: 402,886
Top Poster: BrianSlick (7,990)
Welcome to our newest member, soohyun
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:57 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0