title: Unable to produce correct XML from PHP
body: <p>I have written this code to generate this XML structure, but for some reason it doesn't seems to be working.
  It throws the error :- <code>Undefined variable: operationtype in C:\wamp\www\sms-gateway\dev\testxml.php on line 11</code> and <code>Call to a member function appendChild() on a non-object in C:\wamp\www\sms-gateway\dev\testxml.php on line 11</code></p>
  
  <p>I'm using php's DOMDocument library, which I don;t have any experience with.
  Here's what I need to generate :- 
  <img src="https://i.stack.imgur.com/4JYCk.png" alt="enter image description here"></p>
  
  <p>Here's my code :-</p>
  
  <pre><code>function gen_xml($number,$message,$smssender)
  {
      /* create a dom document with encoding utf8 */
      $domtree = new DOMDocument('1.0', 'UTF-8');
  
      /* create the root element of the xml tree */
      $xmlRoot = $domtree-&gt;createElement("sms-teknik");
      /* append it to the document created */
      $xmlRoot = $domtree-&gt;appendChild($xmlRoot);
  
  
      $operationtype-&gt;appendChild($domtree-&gt;createElement('operationtype','0'));
      $flash-&gt;appendChild($domtree-&gt;createElement('flash','0'));
      $multisms-&gt;appendChild($domtree-&gt;createElement('multisms','0'));
      $maxmultisms-&gt;appendChild($domtree-&gt;createElement('maxmultisms','0'));
      $compresstext-&gt;appendChild($domtree-&gt;createElement('compresstext','0'));
      $smssender-&gt;appendChild($domtree-&gt;createElement('smssender',$smssender));
      $deliverystatustype-&gt;appendChild($domtree-&gt;createElement('deliverystatustype','0'));
      $usereplynumber-&gt;appendChild($domtree-&gt;createElement('usereplynumber','0'));
      $usereplyforwardtype-&gt;appendChild($domtree-&gt;createElement('usereplyforwardtype','0'));
      $usee164-&gt;appendChild($domtree-&gt;createElement('usee164','0'));
  
  
      $item=$domtree-&gt;createElement("items");
      $item = $domtree-&gt;appendChild($item);
  
      $recipient = $domtree-&gt;createElement("recipient");
      $recipient = $domtree-&gt;appendChild($recipient);
  
      $orgaddress-&gt;appendChild($domtree-&gt;createElement('orgaddress',$number));
      echo $domtree-&gt;saveXML();
  }
  </code></pre>
  
  <p>Any suggestions / help would be greatly appreciated. </p>