I am trying to wrap CDATA for the elements in an xml file.
Another point i missed was, there are some elements with same names those need to be escaped from adding CDATA.
This is the source xml file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<books>
<jndi:binding name="books/cat/action/configs">
<jndi:value type="java.lang.String">
<urlConfig>
<defaults catID="1983" subcatID="1987" method="get" onError="keep"/>
<urlKey name="logo" altURL="def.com">
<address>abc.com</address>
</urlKey>
<urlKey name="logo1" altURL="def.com">
<address>abc.com</address>
</urlKey>
</urlConfig>
</jndi:value>
</jndi:binding>
<jndi:binding name="books/cat/romance/configs">
<jndi:value type="java.lang.String">
<urlConfig>
<defaults catID="1983" subcatID="1987" method="get" onError="keep"/>
<urlKey name="logo" altURL="def.com">
<address>abc.com</address>
</urlKey>
<urlKey name="logo1" altURL="def.com">
<address>abc.com</address>
</urlKey>
</urlConfig>
</jndi:value>
</jndi:binding>
<jndi:binding name="books/cat/thriller/configs">
<jndi:value type="java.lang.String">
abc.com
</jndi:value>
</jndi:binding>
<jndi:binding name="books/cat/classic/configs">
<jndi:value type="java.lang.String">
abc.com
</jndi:value>
</jndi:binding>
</books>
I have tried to use the same trick that @Dimitre Novatchev has mentioned here at How to insert CDATA into XML text markup exported from Access 2003?. But some how that's not working for me.
This is the xsl file that i tried:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:jndi="urn:jboss:jndi-binding-service:1.0" >
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Can some one suggest me how to add CDATA to an element and also need to add an additional line <?xml version="1.0" encoding="ISO-8859-1"?>
at the beginning of CDATA.
Here is the expected out:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<books>
<jndi:binding name="books/cat/action/configs">
<jndi:value type="java.lang.String">
<![CDATA[
<?xml version="1.0" encoding="ISO-8859-1"?>
<urlConfig>
<defaults catID="1983" subcatID="1987" method="get" onError="keep"/>
<urlKey name="logo" altURL="def.com">
<address>abc.com</address>
</urlKey>
<urlKey name="logo1" altURL="def.com">
<address>abc.com</address>
</urlKey>
</urlConfig>
]]>
</jndi:value>
</jndi:binding>
<jndi:binding name="books/cat/romance/configs">
<jndi:value type="java.lang.String">
<![CDATA[
<?xml version="1.0" encoding="ISO-8859-1"?>
<urlConfig>
<defaults catID="1983" subcatID="1987" method="get" onError="keep"/>
<urlKey name="logo" altURL="def.com">
<address>abc.com</address>
</urlKey>
<urlKey name="logo1" altURL="def.com">
<address>abc.com</address>
</urlKey>
</urlConfig>
]]>
</jndi:value>
</jndi:binding>
<jndi:binding name="books/cat/thriller/configs">
<jndi:value type="java.lang.String">
abc.com
</jndi:value>
</jndi:binding>
<jndi:binding name="books/cat/classic/configs">
<jndi:value type="java.lang.String">
abc.com
</jndi:value>
</jndi:binding>
</books>