title: PHP DOMdocument problems (characters, file)
body: <p>I've extracted the categories you see on <a href="http://robot-domestici.it" rel="nofollow noreferrer">the left of this page</a> by creating and exploring the DOM tree of the page. Now I want to create a new DOM to store it on my server and reload it locally and speed-up the whole process. I decided to do that while exploring the original DOM. The exploration of the original DOM works, so assume that the parameters are correct.</p>
  
  <p>I write this code to create the DOM:   </p>
  
  <pre><code>$curr_lev=1;
  $mydom=new DOMdocument();
  $curr_parent=$mydom-&gt;createElement('products');
  function create_dom($name, $link, $lev){
      global $curr_lev;
      global $curr_parent;
      global $mydom;
      switch ($lev){
          case $curr_lev:
              $curr_parent-&gt;appendChild($mydom-&gt;createElement($name, $link));
              break;
          case $curr_lev-1:
              $curr_parent=$curr_padre-&gt;parentNode;
              $curr_parent-&gt;appendchild($mydom-&gt;createElemnt($name, $link));
              break;
          case $curr_lev+1:
              $curr_parent=$curr_padre-&gt;lastChild;
              $curr_parent-&gt;appendchild($mydom-&gt;createElement($name, $link));
              break;   
      }
      $curr_lev=$lev;
  }
  
  $mydom-&gt;formatOutput=TRUE;
  $mydom-&gt;saveHTMLFile("products.xml");
  </code></pre>
  
  <p>i try to give an explanation: <code>create_dom()</code> it's called for each node of the original DOM. <code>$lev</code> indicates the level of the new node, <code>$curr_lev</code> it's the level of the last added node, so if they are equal last node added and the current node are child of the same father, if <code>$lev &lt; $curr_lev</code> we have to go back of one level and the new added node is "brother" of the father of the last added, if <code>$lev &gt; $curr_lev</code> the current node is child of the last node added.</p>
  
  <p>The first problem is that when I execute I get this error:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'DOMException' with message 'Invalid Character Error' in C:\Users\Jacopo\Dropbox\Tirocinio\xampp-portable\htdocs\sites\prova\cerca categorie.php:71<br>
    Stack trace:<br>
    #0 C:\Users\Jacopo\Dropbox\Tirocinio\xampp-portable\htdocs\sites\prova\cerca categorie.php(71): DOMDocument->createElement('/joomla/compone...', 'Arduino')<br>
    #1 C:\Users\Jacopo\Dropbox\Tirocinio\xampp-portable\htdocs\sites\prova\cerca categorie.php(30): create_dom('Arduino', '/joomla/compone...', 1)<br>
    #2 C:\Users\Jacopo\Dropbox\Tirocinio\xampp-portable\htdocs\sites\prova\cerca categorie.php(38): visita_raff(Object(DOMElement), 1, 'dl')<br>
    #3 C:\Users\Jacopo\Dropbox\Tirocinio\xampp-portable\htdocs\sites\prova\cerca categorie.php(96): visita_raff(Object(DOMElement), 0, '')<br>
    #4 C:\Users\Jacopo\Dropbox\Tirocinio\xampp-portable\htdocs\sites\prova\index.php(21): include('C:\Users\Jacopo...') #5 {main} thrown in C:\Users\Jacopo\Dropbox\Tirocinio\xampp-portable\htdocs\sites\prova\cerca categorie.php on line 71</p>
  </blockquote>
  
  <p><code>$name</code> usually look like "arduino kit"  and  <code>$link</code> is like "/joomla/componenent/virtuamart/..."</p>
  
  <p>I've tried converting it to UTF-8 but it wont work</p>
  
  <p>Also I've tried to do a test and write this code:</p>
  
  <pre><code>function create_xml(){
      $mydom=new DOMdocument("1.0", "ISO-8859-1");
      $primoElem=$mydom-&gt;createElement('foo');
      $primoElem-&gt;appendChild($mydom-&gt;createElement('arduinio', 'http:arduino'));
      $mydom-&gt;formatOutput=TRUE;
      return $mydom-&gt;saveXML("foo.xml");
  }
  </code></pre>
  
  <p>I get no error <code>saveXML()</code> returns 1, but nothing is written to the file!</p>
  
  <p>What am I doing wrong? Please consider that is the first time I work with those things so be gentle :)</p>