public
Last active — forked from bxt/formatXml.php

  • Download Gist
formatXml.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/usr/bin/php5
<?php
 
if (!isset($argv)||$argc!=2||$argv[1]=='-h'||$argv[1]=='--help') {
echo <<<EOH
usage :
formatXMLNicely.php unformated.xml > formated.xml
 
EOH;
} else {
$file=$argv[1];
if (file_exists($file)) {
if (is_file($file)) {
$xml = simplexml_load_file($argv[1]);
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
if ($domnode = dom_import_simplexml($xml)) {
$domnode = $doc->importNode($domnode, true);
$domnode = $doc->appendChild($domnode);
echo $doc->saveXML();
} else {print ("Error while parsing. \n");}
} else {echo "Error: \"$file\" is a directory. \n";}
} else {echo "Error: No such file or directory: \"$file\" \n";}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.