<?php
$xml= new SimpleXMLElement('<root></root>');
$xml->father['name']= 'Fathers name'; // creates automatically a father tag with attribute name
$son= $xml->father->addChild('son'); // uses the first father tag
$son['name']= 'first son';
$otherSon= $xml->father->addChild('son'); // uses the first father tag but now, in a second son tag
$otherSon['name']= 'second son'; //echo htmlentities($xml->asXML());
echo $xml->asXML();?>
我用上边程序新建xml文件并打印,但结果挤在一块没法肉眼看清
<?xml version="1.0"?>
<root><father name="Fathers name"><son name="first son"/><son name="second son"/></father></root>
如何才能使结果缩进可读呢?
$xml= new SimpleXMLElement('<root></root>');
$xml->father['name']= 'Fathers name'; // creates automatically a father tag with attribute name
$son= $xml->father->addChild('son'); // uses the first father tag
$son['name']= 'first son';
$otherSon= $xml->father->addChild('son'); // uses the first father tag but now, in a second son tag
$otherSon['name']= 'second son'; //echo htmlentities($xml->asXML());
echo $xml->asXML();?>
我用上边程序新建xml文件并打印,但结果挤在一块没法肉眼看清
<?xml version="1.0"?>
<root><father name="Fathers name"><son name="first son"/><son name="second son"/></father></root>
如何才能使结果缩进可读呢?
echo str_replace('>', ">\n", $xml->asXML());