Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transform CDATA 1

Status
Not open for further replies.

klunde

IS-IT--Management
Dec 15, 2004
63
SE
Is there an easy way to transform a XML document with CDATA values into a equal XML document without use of CDATA?

</Morten>
 
xml file with cdata section is represented internally as if there is none. Hence a simple identity transformation will bring the one with cdata to one without.

For instance, with a simple identity transformation from w3c spec:
[tt]
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:eek:utput method="xml" version="1.0" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
[/tt]
You would bring an xml file, such as this:
[tt]
<?xml version="1.0" encoding="utf-8"?>
<root>
<cdata_gt_operator><![CDATA[ > ]]></cdata_gt_operator>
<entity_ref_gt_operator> &gt;</entity_ref_gt_operator>
<char_ref_gt_operator> &#x3E; </char_ref_gt_operator>
</root>
[/tt]
to an output xml file like this.
[tt]
<?xml version="1.0" encoding="utf-8"?>
<root>
<cdata_gt_operator> &gt; </cdata_gt_operator>
<entity_ref_gt_operator> &gt;</entity_ref_gt_operator>
<char_ref_gt_operator> &gt; </char_ref_gt_operator>
</root>
[/tt]
All in all, an identity tranformation would mostly do. The rest is to make the output looking good.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top