title: reading an XML file in a C++ program
body: <p>I'm trying to read an XML file in my C++ program. The XML file looks something like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;myprogram&gt;
  &lt;configuration&gt;
  &lt;window&gt;
  &lt;height&gt; 300 &lt;/height&gt;
  &lt;width&gt; 500 &lt;/width&gt;
  &lt;/window&gt;
  &lt;/configuration&gt;
  &lt;/myprogram&gt;
  </code></pre>
  
  <p>Right now I can look at the XML file and try to read it like this:</p>
  
  <pre><code>ifstream in("mydata.xml");
  
  //ignore the &lt;?xml line
  in.ignore(200, '\n');
  
  //i know that the first value i want is the window height so i can ignore &lt;myprogram&gt; &lt;configuration&gt; and &lt;window&gt;
  
  //ignore &lt;myprogram&gt;
  in.ignore(200, '\n');
  
  //ignore &lt;configuration&gt;
  in.ignore(200, '\n');
  
  //ignore &lt;window&gt;
  in.ignore(200, '\n');
  
  string s; int height;
  
  //okay, now i have my height
  in &gt;&gt; s &gt;&gt; height;
  </code></pre>
  
  <p>In general this seems like a bad idea and it really limits how the XML file can be modified. The above solution is very manual and if anything in the XML changes it seems that the entire method of reading it would have to be changed.</p>
  
  <p>Is there a better way to do this?</p>