Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

output as XML to browser and indent

Status
Not open for further replies.

csbdeady

Programmer
May 18, 2002
119
GB
I am using SimpleXML as follows:

Code:
$result = $objSimpleXML->asxml();
echo "<pre>".htmlspecialchars($result)."</pre>"

to output some XML to the browser window, however it is appearing as:

<a><b><c></c></b></a>

but I would like it to appear indented (and thus readable!):

<a>
<b>
<c></c>
</b>
</a>

I know XSL and indent="yes" but I am wondering if there is a nice quick easy SimpleXML way to do this without an XSL stylesheet?

Thanks
-C
 
...such as pass it through tidy extension.
[tt]
$result = $objSimpleXML->asxml();
$tidy=new tidy();
$config=array("input-xml"=>true,"indent"=>4,"output-xml"=>true);
$tidy->parseString($result,$config);
echo "<pre>".$tidy."</pre>";
[/tt]
 
Forgotten to apply escaping at the last line. It should be read like this.
[tt] echo "<pre>".[blue]htmlspecialchars($tidy)[/blue]."</pre>";[/tt]
 
Tidy is the perfect answer, but having just checked it is unfortunately not available on the ISP in question :(
I may just have to do a good-ole fashioned XSL transformation *sigh*.
-C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top