cancel
Showing results for 
Search instead for 
Did you mean: 

Reading the data from CDATA.

Former Member
0 Kudos

Hi Experts, attn: Stefan.

I have a requirement to convert a string XML to XML using XSLT. With the inputs from Stefan I have got my XSLT mapping working fine and tested it in XMLSpy. It works fine.

The problem is, when I test my Interface mapping in PI and input test XML in a string Field, PI on its own, wraps data into CDATA tag as.

<?xml version="1.0" encoding="UTF-8"?>

<ns0:MT_SourceString xmlns:ns0="http://abc.com">
   <Str><![CDATA[<catalog>
<cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year></cd> 
<cd> <title>Empire Burlesque2</title> <artist>Bob Dylan2</artist> <country>USA</country> <company>Columbia2</company> <price>10.90</price> <year>1985</year> </cd> 
<cd> <title>Empire Burlesque3</title> <artist>Bob Dylan3</artist> <country>USA</country> <company>Columbia3</company> <price>10.90</price> <year>1985</year> </cd> 
</catalog>
]]>

Now XSLT ignores all the data in CDATA and i get nothing in output.

<?xml version="1.0" encoding="UTF-8"?><ns0:MT_TargetCatalog xmlns:a="http://www.sdn.com/xslt" xmlns:ns0="http://abc.com"/>

XSLT Code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://www.sdn.com/xslt">
<xsl:output method="xml" omit-xml-declaration="no"/>
<xsl:template match="/">
<ns0:MT_TargetCatalog xmlns:ns0="http://abc.com">
<xsl:for-each select="//cd">
<xsl:copy-of select="."  />
</xsl:for-each>
</ns0:MT_TargetCatalog>
</xsl:template>
</xsl:stylesheet>

Please sugest how can I read the data from CDATA tag of XML?

Kind Regards,

Abhi.

Accepted Solutions (0)

Answers (2)

Answers (2)

stefan_grube
Active Contributor
0 Kudos

> The problem is, when I test my Interface mapping in PI and input test XML in a string Field, PI on its own, wraps data into CDATA tag as.

Now I see the point. You cannot test like this.

in the test tab click on "source test view"

provide the whole XML here.

Former Member
0 Kudos

The first code snippet in my post is a code from : "source text view " .

The Test XML entered by me was

<catalog>
	<cd>
		<title>Empire Burlesque</title>
		<artist>Bob Dylan</artist>
		<country>USA</country>
		<company>Columbia</company>
		<price>10.90</price>
		<year>1985</year>
	</cd>
	<cd>
		<title>Empire Burlesque2</title>
		<artist>Bob Dylan2</artist>
		<country>USA</country>
		<company>Columbia2</company>
		<price>10.90</price>
		<year>1985</year>
	</cd>
<cd>
		<title>Empire Burlesque3</title>
		<artist>Bob Dylan3</artist>
		<country>USA</country>
		<company>Columbia3</company>
		<price>10.90</price>
		<year>1985</year>
	</cd>
</catalog>

Do you wanna point out that the PI will not add CDATA in real scenario??

I have not configured complete scenario as sender system is not yet ready to send data.

stefan_grube
Active Contributor
0 Kudos

> Do you wanna point out that the PI will not add CDATA in real scenario??

Yes, PI does not add any CDATA for an imcoming XML message.

Former Member
0 Kudos

Ok, I will try with End to End scenario.

But as i have mentioned before it will not be a xml message, the input will be a XML passed as a string in a RFC parameter of type string. I hope it doesnt make any difference and PI will pass on the XML string as it is i.e. w/o wrapping it in CDATA.

Thanks Stefan.

stefan_grube
Active Contributor
0 Kudos

> Now XSLT ignores all the data in CDATA and i get nothing in output.

This is correct behaviour:

http://www.w3.org/TR/2008/REC-xml-20081126/#sec-cdata-sect

there is nothing that you can do here.

Former Member
0 Kudos

Does that means XSLT cannot be used to convert XML String to XML???

Isn't there any work around to prevent PI from wrapping data in CDATA Tag?