Set WeberTrivia.com to be my default homepage.   Suggest a Question                                               

Suggest A Question : :  Frequently Asked Questions : :  Search : :  Relevant Manuals : : 
PHP Questions : :  Linux Questions : :  MySQL Questions : : 
home  [ Login ] 

Example

Example -- Example for the usage of XML_Beautifier

Basic example

Let's assume, you've got an XML document that is really badly formatted:

<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE page [     <!ENTITY foo SYSTEM "foo.xml">     <!ENTITY bar SYSTEM "bar.xml"> ]> <document title="Current News"> <meta project="none" foo="bar">     <keywords/><description/> <author>Stephan Schmidt</author> <getMetaNav/> </meta> <page label="PHP Application Tools" sublabel="Current News"> <?PHP     for($i = 0; $i < count($_GET); $i++) {         echo    $_GET[$i]."<br>";     } ?> &foo;&bar; <intro>    <!-- This Comment has more     than one line.                     -->         <introtitle>Welcome to PHP Application Tools &amp; PEAR!</introtitle> <para>         If you're new to pat, and would like         <!-- This is a comment in a single line that contains an &amp; -->          to know                    what we do                    here, take a look at                    <link url=          "/about/project.xml">          "About Pat"</link>  or check out the <link url="/about/projectsOverview.xml">"projects overview"</link>. Otherwise, you probably know your way  around the site already <smiley type="smile"/> </para>                                             </intro> </page> </document>

All you have to do is to use XML_Beautifier, pass the filename of the original file and the filename for the new file:

require_once "XML/Beautifier.php"; $fmt = new XML_Beautifier(); $result = $fmt->formatFile('originalFile.xml', 'beautifiedFile.xml');  if (PEAR::isError($result)) {     echo $result->getMessage();     exit(); } echo "File beautified, awaiting orders!<br />";

And voila, your document looks nice:

<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE page [     <!ENTITY foo SYSTEM "foo.xml">     <!ENTITY bar SYSTEM "bar.xml"> ]> <document title="Current News">     <meta foo="bar" project="none">         <keywords />         <description />         <author>Stephan Schmidt</author>         <getMetaNav />     </meta>     <page label="PHP Application Tools" sublabel="Current News">         <?PHP         for($i = 0; $i < count($_GET); $i++) {                 echo    $_GET[$i]."<br>";             }         ?>         &foo;         &bar;         <intro>             <!--                 This Comment                 has more                 than one line.             -->             <introtitle>Welcome to PHP Application Tools &amp; PEAR!</introtitle>             <para>                 If you&apos;re new to pat, and would like                 <!-- This is a comment in a single line that contains an &amp; -->                 to know what we do here, take a look at                 <link url="/about/project.xml">&quot;About Pat&quot;</link>                 or check out the                 <link url="/about/projectsOverview.xml">&quot;projects overview&quot;</link>                 . Otherwise, you probably know your way around the site already                 <smiley type="smile" />             </para>         </intro>     </page> </document>
Who's Online
Guest Users: 5
Google
Web
WeberTrivia
WeberDev
WeberForums
 Free Sample Chapters  Free Sample Chapters
  Deliver First Class Web Sites: 101 Essential Checklists
Want to learn how to make your web sites usable and accessible? Want to ensure that your sites meet current best practice, without spending hours trawling through incomprehensible specifications and recommendations from dozens of different books, research papers, and web sites? Want to make sure that the sites you build are "right the first time," requiring no costly redevelopments?

More Sample Chapters

PHP General