Xml: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 8: | Line 8: | ||
<source lang="bash"> |
<source lang="bash"> |
||
xmllint --format doc.xml |
xmllint --format doc.xml |
||
XMLLINT_INDENT=" " xmllint --format doc.xml |
|||
XMLLINT_INDENT=$'\t' xmllint --format doc.xml | sponge doc.xml |
|||
</source> |
</source> |
||
Revision as of 17:45, 8 November 2019
Links
Tips
Format XML document
Using xmllint from package libxml2-utils [1]:
xmllint --format doc.xml
XMLLINT_INDENT=" " xmllint --format doc.xml
XMLLINT_INDENT=$'\t' xmllint --format doc.xml | sponge doc.xml
Using xsltproc and XSLT stylesheet. This requires an intermediate XSLT document:
cat > indent.xslt << __HERE__
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:transform>
__HERE__
xsltproc indent.xslt doc.xml