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 & PEAR!</introtitle> <para> If you're new to pat, and would like <!-- This is a comment in a single line that contains an & --> 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:
<?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 & PEAR!</introtitle> <para> If you're new to pat, and would like <!-- This is a comment in a single line that contains an & --> 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>
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?