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

Close

please start me off in the right direction

Developer
2009-06-08
2013-05-20
  • 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  -->

    <items>
        <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.">
    </items>
    ___________________________

    I have, in my C++ file:

    TiXmlDocument doc( "HolyGrail.xml" );
    doc.LoadFile();
    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
      2009-06-09

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

       
    • Jay Lash
      Jay Lash
      2009-06-09

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

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

       
    • Lee Thomason
      Lee Thomason
      2009-06-15

      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.

      lee