title: Adding element to XML schema PHP
body: <p>I have to add a new element to the existing XML schema. My existing XML schema looks like this.</p>
  
  <pre><code>&lt;xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet"&gt;
  &lt;xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt;
              &lt;xs:element name="sample"&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element name="id1" type="xs:int" minOccurs="0"/&gt;
                          &lt;xs:element name="id2" type="xs:string" minOccurs="0"/&gt;
                          &lt;xs:element name="id3" type="xs:int" minOccurs="0"/&gt;
  </code></pre>
  
  <p>Now i need the resultant schema , like this..</p>
  
  <pre><code>  &lt;xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet"&gt;
  &lt;xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt;
              &lt;xs:element name="sample"&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                        &lt;xs:element name="id1" type="xs:int" minOccurs="0"/&gt;
                        &lt;xs:element name="id2" type="xs:string" minOccurs="0"/&gt;
                        &lt;xs:element name="id3" type="xs:int" minOccurs="0"/&gt;
                        &lt;xs:element name="id4" type="xs:int" minOccurs="0"/&gt;
  </code></pre>
  
  <p>New Element <code>id4</code> to be added under the element sample. I tried <code>createElement</code> and <code>appendChild</code>, its not working properly. Help me to solve this prob</p>
  
  <p>This is the code which i have tried to add a new element</p>
  
  <pre><code>$schema_dom=new DOMDocument($schemaxml); 
  $respondent=
  $schema_dom-&gt;getElementsByTagName('sample');
  firstname=$schema_dom-&gt;createElement('id4'); 
  $respondent-&gt;appendChild($firstname);
  $schemaobj=$schema_dom-&gt;saveXML();
  </code></pre>
  
  <p>Here in the above code, $schemaxml is a string variable contains the XML schema.above code gives me an error saying that <code>Fatal error: Call to undefined method DOMNodeList::appendChild()</code>. </p>