PHP XML ident formatter

<?php /** * $rawXmlData is not formatted XML data (without idents and line breaks), like this: * * ```xml * <testData><item>1</item><item>2</item></testData> * ``` * * In output you will se like this: * * ```php * <?xml version="1.0" encoding="UTF-8"?> * <testData> * <item>1</item> * <item>2</item> * </testData> * ``` */ $dom = new DOMDocument(); $dom->preserveWhiteSpace = false; if ($dom->loadXML($rawXmlData) === true) { $dom->formatOutput = true; echo $dom->saveXML(); } else { echo $rawXmlData; }
Generates human-friendly XML view from raw XML data without idents and line breaks.

1 Response

I can't paste spaces in my description :( It must be:

<?xml version="1.0" encoding="UTF-8"?>
<testData>
__<item>1</item>
__<item>2</item>
</testData>

Where __ - is spaces.

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.