title: TinyXML2 Parse data within the same element in C++
body: <p>I have an XML file like this:</p>
  
  <pre><code>&lt;Aircraft callsign="MS842" type="B703"&gt;
    &lt;State&gt;89220.4892904 52914.9322014 8229.6 0 0 4.36332312999 0 0 70.0 270.741736633 0&lt;/State&gt;
    &lt;AutoPilot&gt;
      &lt;Mode setpoint="174.89485525" type="MODE_SPD_CAS"/&gt;
      &lt;Mode setpoint="8229.6" type="MODE_ALT_HLD"/&gt;
      &lt;Mode setpoint="4.36332312999" type="MODE_HDG_SEL"/&gt;
    &lt;/AutoPilot&gt;
  &lt;/Aircraft&gt;
  </code></pre>
  
  <p>I need to parse the data within the child element "State". What I need is data from specific locations within that element:</p>
  
  <ol>
  <li>1st data: px = 89220.4892904</li>
  <li>2nd data: py = 52914.9322014</li>
  <li>6th data: ph = 4.36332312999</li>
  </ol>
  
  <p>where px, py and ph are some variables of type double.</p>
  
  <p>If I run the following:</p>
  
  <pre><code>TiXmlElement* subelement = 0;
  subelement = xmlac-&gt;FirstChildElement("State");
  std::cout &lt;&lt; "Elem : " subelement[0] &lt;&lt; endl;
  </code></pre>
  
  <p>I get the following:</p>
  
  <pre><code>Elem : &lt;State&gt;89220.4892904 52914.9322014 8229.6 0 0 4.36332312999 0 0 70.0 270.741736633 0&lt;/State&gt;
  </code></pre>
  
  <p>Is there a way like:</p>
  
  <pre><code>double px=0.0, py=0.0, ph=0.0;
  px = subelement[0][0]
  py = subelement[0][1]
  ph = subelement[0][2]
  </code></pre>
  
  <p>which does the job? (I tried the above code. I get something called as a fragmentation error.)</p>
  
  <p>NOTE:</p>
  
  <ul>
  <li>My experience in C++ is minimal. If the concepts are too cumbersome, please indicate sources for your answers/assumptions</li>
  <li>Language: C++</li>
  <li>xml parser: tinyxml</li>
  </ul>
  
  <p>Thanks.</p>
  
  <p>EDIT:
  Found the solution. See below</p>