LexPl has asked for the wisdom of the Perl Monks concerning the following question:
Is there an easy way to indent an unindented XML file?
Of course, significant whitespace between two adjacent elements or in mixed content should not be obscured or lost
The data have an encoding ISO-8859-1 and contain tons of XML entities defined in a DTD with external entity declarations in a subdirectory
sample input
<?xml version="1.0" encoding="ISO-8859-1"?><root><para><pnum>1</pnum><ptext>This is a sample of a very specific text <emph>called</emph> <term>description</term> which has 2 subtypes: <list><item><term>1.</term><p>precise</p></item><item><term>2.</term><p>fuzzy</p></item></list></ptext></para></root>
The output should look like this:
<?xml version="1.0" encoding="ISO-8859-1"?> <root> <para> <pnum>1</pnum> <ptext>This is a sample of a very specific text <emph>called</ +emph> <term>description</term> which has 2 subtypes: <list> <item> <term>1.</term> <p>precise</p> </item> <item> <term>2.</term> <p>fuzzy</p> </item> </list> </ptext> </para> </root>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Indent XML data
by Anonymous Monk on Jan 22, 2025 at 16:34 UTC | |
by LexPl (Beadle) on Jan 23, 2025 at 13:50 UTC | |
by Corion (Patriarch) on Jan 23, 2025 at 13:53 UTC | |
by LexPl (Beadle) on Jan 22, 2025 at 16:45 UTC | |
by marto (Cardinal) on Jan 22, 2025 at 16:52 UTC | |
by karlgoethebier (Abbot) on Jan 22, 2025 at 16:51 UTC | |
Re: Indent XML data
by Fletch (Bishop) on Jan 22, 2025 at 16:32 UTC | |
by LexPl (Beadle) on Jan 22, 2025 at 16:43 UTC |