Can elements be parsed in order? See example

Developer
2012-01-11
2013-05-20
  • Robert Kirnum
    Robert Kirnum
    2012-01-11

    Given the example below (based on the tutorial), can the <shapes> children elements be parsed in order?  Based on the sample code I can currently only parse all the <circle> elements followed by all the <point> elements (or vice versa).  I need to be able to parse the elements in the order they are shown (<circle> 1, <point> 1, <circle> 2, <point> 2, etc.).  Is this possible??  If so, please help!

    <<
    <?xml version="1.0" ?>
    <shapes>
    <circle name="int-based" x="20" y="30" r="50" />
    <point name="float-based" x="3.5" y="52.1" />
    <circle name="int-based" x="20" y="30" r="50" />
    <point name="float-based" x="3.5" y="52.1" />
    </shapes>
    >>

     
  • Jay Lash
    Jay Lash
    2012-01-11

    How are you looping over the children that results in all of the circles followed by all of the points?

    You should be able to use either FirstChild() / NextSibling() or IterateChildren() to do what you want. 
    There is an example fragment in the docs for IterateChildern() (link)

     
  • Robert Kirnum
    Robert Kirnum
    2012-01-11

    Yes, I was using the NextSibling() method.  However, I was not able to figure out how to differentiate between one element type and another so I was providing the element name to the NetSibling method.  I found that there exists the Value() method which gives me the text of the element as pElement->Value().  I can now use this to do a string compare and differentiate between elements as shown. . . 

       if ("circle" == string(pElement->Value())
       {
       }
       else if ("point" == string(pElement->Value())
       {
       }

    Thanks!