title: Output XMLWriter to XML file
body: <p>I am currently using XMLWriter to display an xml file. However I would like to know how I could export the output to a .xml file.</p>
  
  <p>My current code is:</p>
  
  <pre><code>$res = mysql_query($sql);
  
  $xml = new XMLWriter();
  
  $xml-&gt;openURI("php://output");
  $xml-&gt;startDocument();
  $xml-&gt;startElement('stores');
  
  while ($row = mysql_fetch_assoc($res)) {
  //loads of code
  }
  $xml-&gt;endElement();
  
  $xml-&gt;flush();
  </code></pre>