Need help Parsing xml file

Discussion in 'iOS Programming' started by Pietje321, Feb 2, 2009.

  1. Pietje321 macrumors newbie

    Joined:
    Feb 2, 2009
    #1
    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..
     
  2. jnic macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #2
    I could be wrong but I'm pretty sure NSXMLParser handles self-closing tags correctly.
     
  3. Pietje321 thread starter macrumors newbie

    Joined:
    Feb 2, 2009
    #3
    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
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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?:
    Code:
    <title title="Naam"/>
    <author author ="Auteur"/>
    <summary summary ="Samenvatting"/>
    
    P.S. Are you Dutch by the way, Pietje?
     

Share This Page