PDA

View Full Version : Need help Parsing xml file




Pietje321
Feb 2, 2009, 08:32 AM
Hello,

I'm having trouble parsing a xml file correctly.
I know the code for parsing a xml file like this one below:

<Books>
<book id="1">
<title>Naam</title>
<author>Auteur</author>
<summary>Samenvatting</summary>
</book>
</books>

But my question is how can i parse a xml like this one:

<Books>
<book id="1">
<title ="Naam"/>
<author ="Auteur"/>
<summary ="Samenvatting"/>
</book>
</books>

Hope someone can help me with this.

thanks in advance..



jnic
Feb 2, 2009, 08:48 AM
I could be wrong but I'm pretty sure NSXMLParser (http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html) handles self-closing tags correctly.

Pietje321
Feb 27, 2009, 04:48 AM
Yes i now i can do it with the NSXMLPARSER but how can i do that precisly..

can you show me some code so i can get underway..

thanx in advance

dejo
Feb 27, 2009, 09:20 AM
parser:didStartElement:namespaceURI:qualifiedName:attributes: should be able to pull in that info, normally, via the attributes parameter. But I suspect it may not work in your case, since I believe your XML is not well-formed; it will think it is either missing the tag name or the attribute key. Can you redo the tagging to be?:
<title title="Naam"/>
<author author ="Auteur"/>
<summary summary ="Samenvatting"/>


P.S. Are you Dutch by the way, Pietje?