XMLFormatter2

XMLFormatter2 is a XML beautifying tool deriving from XML_Formatter originally developed by Žilvinas Šaltys. If you are in need of handling big files you should still resort to that solution, since it reads chunks of data at a time using file streams. Maybe at some point I will integrate that too…. (or maybe I should just simply do it right now).

So what is it about:

  • it is a very small PHP class
  • taking an XML input string
  • fixing XML indentation (indenting being the reason I first looked for the original tool)
  • and finally giving you an nicely formatted XML output string as a result

If you are looking for an easy way to indent XML strings in PHP this is for you. The most common usage example would be a requirement to fix the reading style of some “compressed” XML string you got from a third-party application.

Here a quick usage example:

require_once("XMLFormatter2.php");

$data = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>....';

try {
  $formatter = new XMLFormatter2();
  echo $formatter->format($data);
} catch (Exception $e) {
  echo $e->getMessage(), "\n";
}
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

DOWNLOAD:  XMLFormatter2 (6464 downloads )