P
Pk Z.
Havn't found best soultion to pretty print XML:
REXML: It has pp functionality, but it wrap elements like <a>content</a>
to
<a>
content
</a>
Nokogiri: there is a approch to pp, see ex:
# Pretty print XML
require "nokogiri"
def write(buffer)
xsl =<<XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
XSL
doc = Nokogiri::XML(buffer)
xslt = Nokogiri::XSLT(xsl)
out = xslt.transform(doc)
out.to_xml
end
But nokogiri has another problem, which unwrap CDATA.
Any better solution? Thanks. And apologize for my poor english.
REXML: It has pp functionality, but it wrap elements like <a>content</a>
to
<a>
content
</a>
Nokogiri: there is a approch to pp, see ex:
# Pretty print XML
require "nokogiri"
def write(buffer)
xsl =<<XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
XSL
doc = Nokogiri::XML(buffer)
xslt = Nokogiri::XSLT(xsl)
out = xslt.transform(doc)
out.to_xml
end
But nokogiri has another problem, which unwrap CDATA.
Any better solution? Thanks. And apologize for my poor english.