0

I'm writing to an xml file using PHP function SimpleXMLElement, the xml writes succesfully but is not well formatted, all data is in one line. i would like it to be something like these

<Shoe>
   <brand>Nike</brand>
   <type>Lebron</type>
   <Release Date>2015/02/11</Release Date>
</Shoe>

here is my code, thanks in adavnce.

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><mydoc></mydoc>');
$xml->addAttribute('version', '1.0');
$xml->addChild('datetime', date('Y-m-d H:i:s'));

$person = $xml->addChild('Shoe');
$person->addChild('brand', 'Nike');
$person->addChild('type', 'Jordan');
$person->addChild('Release Date', '2014/05/21');

$person = $xml->addChild('Shoe');
$person->addChild('brand', 'Adidas');
$person->addChild('type', 'Stan Smith');
$person->addChild('Release Date', '2014/0/03');

$xml->saveXML("shoeOrder.xml");
Yung A
  • 239
  • 1
  • 2
  • 12
  • Also [this one](http://stackoverflow.com/questions/1191167/format-output-of-simplexml-asxml) – Michael Berkowski May 08 '14 at 13:39
  • Note that "well formed" (I know, not *formatted*) is a term with its own meaning in XML, and this XML is certainly *well formed* and also well formatted as far as XML is concerned. You simply want to make it more readable to humans. – deceze May 08 '14 at 13:40
  • @MichaelBerkowski the question you refered to is a duplicate already, so that doesn't really help. – Irdrah May 08 '14 at 13:41
  • @MichaelBerkowski Both answers of the second reference can be found in the First one. – Irdrah May 08 '14 at 13:44
  • @Irdrah, "doesn't really help", n answer from you would help..give me a link to the duplicate. – Yung A May 08 '14 at 14:03
  • Why should I provide you another link to the original question, when many others have already given you multiple. It's not my fault that you lack the desire to take any action whatsoever. – Irdrah May 14 '14 at 10:10
  • @Irdrah.. Thanx fr ur enthusiasm bt i solved this a long tym ago, mayb find somethnign else to do. – Yung A May 15 '14 at 09:43

0 Answers0