Menu

Newb Question about Parsing

Developer
2007-08-11
2013-05-20
  • Leeor Dicker

    Leeor Dicker - 2007-08-11

    I hate having to post here and ask because I can usually figure things out using examples... I don't know why but the provided examples in the documents confuse me...

    Anyway, to the point, I am trying to parse the following XML file:

    <?xml version="1.0" ?>
    <tileset name="demo">
        <page filename="demo.bmp">
            <tile name="Grass">
                <rectangle x="0" y="0" w="64" h="32"/>
                <anchor x="31" y="15"/>
                <colorkey r="255" g="0" b="255"/>
            </tile>
            <tile name="Rocky Path">
                <rectangle x="64" y="0" w="64" h="32"/>
                <anchor x="31" y="15"/>
                <colorkey r="255" g="0" b="255"/>
            </tile>
        </page>
        <page filename="tree01.bmp">
            <tile name="Tree Thing 1">
                <rectangle x="0" y="0" w="74" h="79"/>
                <anchor x="35" y="77"/>
                <colorkey r="255" g="0" b="255"/>
            </tile>
        </page>
    </tileset>

    This should be pretty straight forward. Yet, I can't seem to get anything to parse properly... and it's mostly because I don't quite understand the classes behind TinyXML.

    Also, I'm not using STL so therein might lie the problem of why I don't understand the examples.

    I'm not so much looking for exact code rather than a decent explanation of the objects I need to create and which functions to use to get the information stored in the various nodes.

    Thanks again for any help that anybody can provide!

    - Leeor

     
    • Leeor Dicker

      Leeor Dicker - 2007-08-12

      Ok, I think I figured out part of the problem I was having. I changed the XML document to this instead:

      <tileset>
          <name>Demo</name>
          <page>
              <image>demo.bmp</image>
              <tile>
                  <description>Grass 1</description>
                  <rectangle x="0" y="0" w="64" h="32"/>
                  <anchor x="31" y="15"/>
                  <colorkey r="255" g="0" b="255"/>
              </tile>
              <tile>
                  <description>Rocky Path</description>
                  <rectangle x="64" y="0" w="64" h="32"/>
                  <anchor x="31" y="15"/>
                  <colorkey r="255" g="0" b="255"/>
              </tile>
          </page>
          <page>
              <image>tree01.bmp</image>
              <tile>
                  <description>Tree Thing 1</description>
                  <rectangle x="0" y="0" w="74" h="79"/>
                  <anchor x="35" y="77"/>
                  <colorkey r="255" g="0" b="255"/>
              </tile>
          </page>
      </tileset>

      I also have the following code:

      TiXmlDocument doc( tset1.xml" );

      if( doc.LoadFile() )
      {
          MessageBox( NULL, "Couldn't load XML file!", NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL );
          exit(-1);
      }
          
      TiXmlNode* tileSet = 0;
      while( tileSet = doc.IterateChildren( "tileset", tileSet ) )
      {
          MessageBox( NULL, "Found first Node", NULL, MB_OK | MB_TASKMODAL );
      }

      This seems to be pretty straight forward... but the 'while' is never entered. I'm sure that if I can just get it into the 'while' loop I can iterate through the whole document and be able to get all the information I need.

      <sigh>

      Thanks for any help!

       
    • Leeor Dicker

      Leeor Dicker - 2007-08-12

      Ok -- I figured it out.

      I had a logic error in this line:

      if( doc.LoadFile() )

      It should instead be:

      if( !doc.LoadFile() )

      Everything is all squared away now... ^_^

       

Log in to post a comment.