title: Tinyxml2 root setattribute
body: <p>I have been trying to set an attribute for the root in an XML doc using tinyxml2.</p>
  
  <p>In tinyxml, the following code</p>
  
  <pre><code>TiXmlDocument doc;
  
  TiXmlElement * root = new TiXmlElement( "ROOT" );
  
  
  root-&gt;SetAttribute("msg","ImFree");
  doc.LinkEndChild( root );
  
  TiXmlElement * element = new TiXmlElement( "CHILD" );
  TiXmlText * text = new TiXmlText( "Message" );
  element-&gt;LinkEndChild( text );
  root-&gt;LinkEndChild( element );
  
  
  doc.SaveFile( "foo.xml" );
  </code></pre>
  
  <p>generates the following xml file:</p>
  
  <pre><code>&lt;ROOT msg="ImFree"&gt;
      &lt;CHILD&gt;Message&lt;/CHILD&gt; 
  &lt;/ROOT&gt;
  </code></pre>
  
  <p>However I still have no idea how to set the attribute of the root in tinyxml2. I have the following code:</p>
  
  <pre><code>tinyxml2::XMLDocument xml_doc;
  
  tinyxml2::XMLNode * p_root = xml_doc.NewElement("ROOT");
  xml_doc.InsertFirstChild(p_root);
  
  
  tinyxml2::XMLElement * p_element = xml_doc.NewElement("CHILD");
  p_element-&gt;SetText("Message");
  p_root-&gt;InsertEndChild(p_element);
  </code></pre>
  
  <p>Which generates :</p>
  
  <pre><code>&lt;ROOT&gt;
      &lt;CHILD&gt;Message&lt;/CHILD&gt;
  &lt;/ROOT&gt;
  </code></pre>
  
  <p>Now if I write <code>p_root-&gt;SetText();</code>, <code>p_root-&gt;SetValue();</code> or <code>SetAttribute</code>, all give an error that <code>class tinyxml2::XMLNode has no member named SetText</code> or <code>SetValue</code> or <code>SetAttribute</code>.</p>
  
  <p>I searched hard to find the answer online, but couldn't find it.</p>
  
  <p>Thanks</p>
  
  <p>Cheers</p>