on 02-01-2011 11:51 PM
Hi All,
I have a structure like
<?xml version="1.0" encoding="UTF-8"?>
<ResponsePayload>
<RespString><?xml version="1.0" encoding="UTF-8"?><Devices>
<Device><Name>Nuts</Name><Units>5</Units></Device><Device><Name>Bulbs</Name><Units>6</Units></Device><Device><Name>Screws</Name><Units>3</Units></Device></Devices></RespString>
</ResponsePayload>
In the "RespString" element I have the xml string. I need to map this xml string to a node in my target mapping. Am having a XML in a single string in mah request and wanna convert that into a XML node in an xml
<?xml version="1.0" encoding="UTF-8"?>
<ResponsePayload>
<Devices>
<Device><Name>Nuts</Name><Units>5</Units></Device>
<Device><Name>Bulbs</Name><Units>6</Units></Device>
<Device><Name>Screws</Name><Units>3</Units></Device>
</Devices>
</ResponsePayload>
Thx in advance
Ravijeet
Hello Udo,
we have a simailar requirement where the source and target structures that I have created for test are belw :
Souce structure sent :
<?xml version="1.0" encoding="UTF-8"?>
<ResponsePayload>
<RespString><?xml version="1.0" encoding="UTF-8"?>
<Devices>
<Device>1</Device>
<Name>1</Name>
</Devices></RespString>
</ResponsePayload>
Target:
<?xml version="1.0" encoding="UTF-8"?>
<Devices>
<Device/>
<Name/>
</Devices>
I used the below steps as suggested by you:
XSLT 1:
<?xml version="1.0" encoding="UTF-8" ?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" />
- <xsl:template match="/">
- <xsl:for-each select="//RespString">
<xsl:value-of select="." disable-output-escaping="yes" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
xslt 2:
<?xml version="1.0" encoding="UTF-8" ?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:template match="/">
- <ResponsePayload>
<xsl:copy-of select="//Devices" />
</ResponsePayload>
</xsl:template>
</xsl:stylesheet>
Iam getting the below error while executing :
javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: The processing instruction target matching "[xX][mM][lL]" is not allowed
Could you please let me know why this error is occuring?
Thanks
Rajesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ravijeet,
you can reach that with two simple styles:
First one deserializes and avoid getting the XML declaration:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:for-each select="//RespString">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Second maps the root element around...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<ResponsePayload>
<xsl:copy-of select="//Devices"/>
</ResponsePayload>
</xsl:template>
</xsl:stylesheet>
Regards,
Udo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ravijeet,
When I compare input and output, only
<RespString><?xml version="1.0" encoding="UTF-8"?>
and
</RespString>
are missing in output.
Am I right?
Regards,
Raghu_Vamsee
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>>> Am having a XML in a single string in mah request and wanna convert that into a XML node in an xml
Solution: Create java mapping to achieve this. Basically you have to read that element entire xml string and create node and all the structure elements and map it on the target side.
You have to do consecutive mapping. First use message mapping for all the elements except that xml string element. Then this java mapping look for the getElementsByTagName('xmlstring') to fetch th xml string and read the entire string xml and create nodes and subelements according to the data sent in that input xml string
Question: How will you handle if the input string xml has syntax errors?
Hope answered your question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.