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.
My current code is:
$res = mysql_query($sql);
$xml = new XMLWriter();
$xml->openURI("php://output");
$xml->startDocument();
$xml->startElement('stores');
while ($row = mysql_fetch_assoc($res)) {
//loads of code
}
$xml->endElement();
$xml->flush();
Xml; var sts = new XmlWriterSettings() { Indent = true, }; using XmlWriter writer = XmlWriter. Create("data. xml", sts); writer. WriteStartDocument(); writer.
XmlWriter is an abstract class. XmlTextWriter is a specific implementation of XmlWriter .
The XmlWriter class writes XML data to a stream, file, text reader, or string. It supports the W3C Extensible Markup Language (XML) 1.0 (fourth edition) and Namespaces in XML 1.0 (third edition) recommendations.
The XmlReader, XmlWriter and their derived classes contains methods and properties to read and write XML documents. With the help of the XmlDocument and XmlDataDocument classes, you can read entire document. The Load and Save method of XmlDocument loads a reader or a file and saves document respectively.
Use a filename instead of php://output
in the openURI()
method.
$writer = new XMLWriter();
$writer->openURI('test.xml');
$writer->startDocument("1.0");
$writer->startElement("greeting");
$writer->text('Hello World');
$writer->endDocument();
$writer->flush();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With