Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


please start me off in the right direction

  • Hey,

    I'm having trouble understanding how to do very basic, straightforward manipulation of data pulled from an .xml file and the tutorial didn't really give examples that helped me out.  Say I have this data:

    <?xml version="1.0" standalone=no>
    <!-- Monty Python's Holy Grail text adventure version 1.0  -->

        <item name="SHRUBBERY" description="100 pounds of decorative wood that is useless for combat.">
        <item name="SWORD" description="A scimitar that a watery tart lobbed at you.">
        <item name="MAP" description="A map that reads 'North, West, South, West'.  You’re not expect to follow it.">
        <item name="BOOK" description="A Book of Knowledge that resembles Wikipedia.  Has a full section on Laden Swallows.">
        <item name="ORB" description="A fiery orb that’s been said to warm the hearts of even the coldest women.">

    I have, in my C++ file:

    TiXmlDocument doc( "HolyGrail.xml" );
    TiXmlElement* itemList = doc.FirstChildElement("items");

    TiXmlElement* itemEntry = itemList->FirstChildElement("item");
    cout<<itemEntry->Attribute("name");  //this works

    itemEntry = itemEntry->NextSiblingElement("item");
    cout<<itemEntry->Attribute("name");    //this doesn't work.

    I must have a fundamental misunderstanding here.  If NextSiblingElement is not the way to access other "item" elements, what is?   Please help. 

    Thanks in advance.

    • Nicola Civran
      Nicola Civran

      Perhaps your "item" tags are not closed...

    • Jay Lash
      Jay Lash

      Yep, missing close tags looks like the problem to me.  TinyXML thinks you have:

          <item name="SHRUBBERY" ...
              <item name="SWORD" ...
                  <item name="MAP" ...
                      <item name="BOOK" ...
                          <item name="ORB" ...
      <!-- these are all missing

    • Lee Thomason
      Lee Thomason

      General tips:

      1) check your error codes in the source (especially from the LoadFile)
      2) check your source XML in a browser (IE, Firefox) which will show errors in XML visually.