PHP API XML_Beautifier Examples Format XML String

 

- Info:

- This tutorial shows how to use XML_Beautifier to format XML String.

- To see how to set formating options see Format XML String With Options.

- This tutorial is based on http://www.codediesel.com/pear/beautifying-xml-documents/.

 

- Procedure:

- Create test.php

 

test.php

<?php

//ADD PATH TO PEAR TO php.ini PARAMETER include_path.

set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/share/php');

//INCLUDE BAUTIFIER.

require_once "/usr/share/php/XML/Beautifier.php";

//SETUP XML_Beautifier.

$XMLBeautifier = new XML_Beautifier();

//FORMAT XML.

$xml = '<rootNode><foo bar = "pear">hello world!</foo></rootNode>';

$formatedXML = $XMLBeautifier->formatString($xml);

echo $formatedXML;

?>

output

<rootNode>

<foo bar="pear">hello world!</foo>

</rootNode>