That's the task I'm trying to complete right now and I've seen a multitude of ways to do it with PHP in my Google searches and on Stack Overflow. Unfortunately, nothing seems to be working for me. I have no issues loading an existing .xml file with $xml = simplexml_load_file()
and saving it to another directory on the server with $xml->asXML('example.xml')
. But creating one is just not working.
This Stack Overflow page showed it with SimpleXML. I did what the edited answer for that question shows: $doc = new DOMDocument( '1.0' );
$doc->save("thexmlfile.xml");
but that didn't work.
This short video showed $xml = new DomDocument("1.0","UTF-8")
and save it using $string_value = $xml_>saveXML(); $xml->save("example.xml")
but that didn't work.
Here's my latest attempt. No XML file gets created as a result of this.
//Create an xml doc for the adcode folder
$xml = new DOMDocument("1.0","UTF-8");
$ticket = $xml->createElement("ticket");
$ticket = $xml->appendChild($ticket);
$ticketid = $xml->createElement('ticketid', $ticketid);
$ticketid = $ticket->appendChild($ticketid);
$xml->formatOutput = true;
$xml->asXML('code/' . $ticketid . '.xml');