NextSibling not returning NULL?

Developer
CaptNeo
2009-05-27
2013-05-20
  • CaptNeo

    CaptNeo - 2009-05-27

    Hi,

    this is probably some stupid coding error on my part, but it seems to me, that NextSibling does not behave as it should. I'm parsing the following xml (a simple scene graph):

    <?xml version="1.0" ?>
    <Node scale="1.000000">
        <Vector x="0.000000" y="0.000000" z="0.000000" w="1.000000" />
        <Angle angle="0.000000" />
        <Angle angle="0.000000" />
        <Angle angle="0.000000" />
        <Children>
            <Node scale="3.000000">
                <Vector x="-5.000000" y="0.000000" z="0.000000" w="1.000000" />
                <Angle angle="10.000000" />
                <Angle angle="20.000000" />
                <Angle angle="30.000000" />
                <Children />
            </Node>
        </Children>
    </Node>

    So I'm building up a tree of scene graph Nodes and use TinyXml to do so. Everything works fine until the parser reaches the Children tag. Here is the code for that:

        const TiXmlElement* children = tempElement->NextSiblingElement("Children");
        tempElement = children->FirstChildElement("Node");
        while(tempElement)
        {
            this->AddChild(new Node(tempElement));
            tempElement->NextSiblingElement("Node");
        }// end for all child nodes

    The while loop never finishes as tempElement never gets to NULL. According to the documentation it should do so, if there are no more "Node" elements to find in the "Children" element.

    After looking at the Tutorial I tried some alternative conditions, loops and ways to access the next sibling, but nothing seems to work. As I said, I don't really think that there is something wrong with the library, cause I think this is exactly what it is used for every day. But right now, I don't realize what I'm doing wrong.

    Thanks!

     
    • dominik.holler

      dominik.holler - 2009-05-27

      does your code works, if you write
      tempElement = tempElement->NextSiblingElement("Node");

       
    • CaptNeo

      CaptNeo - 2009-05-28

      Thanks Dominic. I knew I would embarrass myself. :-)

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks