title: XMLWrite output a file to same directory as php script
body: <p>Hello here I'm once again. After my last question <a href="https://stackoverflow.com/questions/19376106/xml-parsing-error-resolved-xml-sample">XML parsing error (RESOLVED) XML Sample</a> which really helped me to learn more. I'm running against another brick wall.</p>
  
  <p>My question:
  What I need to do is to write an .xml file in the same directory where my php document is. So when i execute the script it should automatic save an .xml file to the directory where the php file is. Is this possible and how?</p>
  
  <p>Currently I'm trying to output the file using the openURI but when I'm doing that I'm getting the following error(translated from Dutch):</p>
  
  <p>The fun thing is if I use php://output it shows all of it correctly in the browser.</p>
  
  <pre><code>XML-Parse Error: no element found
  Location: xml.php
  Rownumber 1, column 1:
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php
      //SELECTEER ALLES VAN DATABASE PROJECTEN
      $sql = "SELECT * FROM projecten ORDER BY id";
      $res = mysql_query($sql);
  
      //BEGIN XML
      $xml = new XMLWriter();
      $xml-&gt;openURI('file.xml');
      $xml-&gt;setIndentString ( '&amp;#09;' );
      $xml-&gt;startDocument( '1.0', 'UTF-8', 'no' );
      $xml-&gt;setIndent(true);
  
      //FUNCTIE VOOR MAKKELIJKER INVOEREN
      function addNode( $xml, $NodeName, $Value ) {
      $xml-&gt;startElement( $NodeName );
      $xml-&gt;writeCData( $Value );
      $xml-&gt;endElement();      
      }
  
     //START HOOFD ELEMENT
     $xml-&gt;startElement('projecten');
  
      //WHILE LOOP DOOR DATABASE
      while ($row = mysql_fetch_assoc($res)) {
  
              //START PROJECT
              $xml-&gt;startElement('project');
              $xml-&gt;writeAttribute('id', $row['id']);
  
                  addNode( $xml, "id", $row["id"] );
                  addNode( $xml, "projectnaam", $row['projectnaam'] );
                  addNode( $xml, "status", $row['status'] );
                  addNode( $xml, "klantnaam", $row['klantnaam'] );
                  addNode( $xml, "startdatum", $row['startdatum'] );
                  addNode( $xml, "eindddatum", $row['einddatum'] );
  
              //EIND PROJECT
              $xml-&gt;endElement();
      }
  
      //EINDE HOOFD ELEMENT
      $xml-&gt;endElement();
  
      //EINDE DOCUMENT
      $xml-&gt;endDocument(); 
      header('Content-type: text/xml');
      $xml-&gt;flush();
  ?&gt;
  </code></pre>
  
  <p>Thanks in advance, once again...</p>