cancel
Showing results for 
Search instead for 
Did you mean: 

Need help: String to XML

Former Member
0 Kudos

Hi everyone,

Im looking for some assistance regarding string to xml. I wanted to extract the xml from the field 'sendDataReturn'. Is my xsl script correct?

XML in String

<sendDataResponse xmlns="http://service.aes.cust.mic.at" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<sendDataReturn><b><?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> <MicExportResponseMessage xmlns="http://www.mic-cust.com/Webservice/MicExportWS/v1.1"><Connection><connectionID>MICWEBSERVICE</connectionID><partnerID>SAPKLD400</partnerID><dateTime>2008-12-12T09:35:40</dateTime></Connection><Messages><Message><Envelope><messageID>1</messageID><partyID>01</partyID><schemaID>V 1.0 B01</schemaID><sequenceNum>1</sequenceNum><transActionID>970002570-01-TR-V3</transActionID></Envelope><Detail><actionCode><code>ER</code></actionCode><error><errorSource>MIC</errorSource><errorCode>106615</errorCode><errorType>ERR</errorType><errorText>Objekt ist schon in der Datenbank vorhanden</errorText></error></Detail></Message></Messages></MicExportResponseMessage></b></sendDataReturn>

</sendDataResponse>

XSL SCRIPT

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

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://service.aes.cust.mic.at">

<xsl:template match="/">

<xsl:for-each select="//sendDataReturn">

<xsl:value-of select="." disable-output-escaping="yes"/>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

In order to apply an xsl your input needs to be valid xml. In your example this starts at the XML declaration

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<MicExportResponseMessage xmlns="http://www.mic-cust.com/Webservice/MicExportWS/v1.1">

<Connection>

<connectionID>MICWEBSERVICE</connectionID>

<partnerID>SAPKLD400</partnerID>

<dateTime>2008-12-12T09:35:40</dateTime>

</Connection>

<Messages>

<Message>

<Envelope>

<messageID>1</messageID>

<partyID>01</partyID>

<schemaID>V 1.0 B01</schemaID>

<sequenceNum>1</sequenceNum>

<transActionID>970002570-01-TR-V3</transActionID>

</Envelope>

<Detail>

<actionCode>

<code>ER</code>

</actionCode>

<error>

<errorSource>MIC</errorSource>

<errorCode>106615</errorCode>

<errorType>ERR</errorType>

<errorText>Objekt ist schon in der Datenbank vorhanden</errorText>

</error>

</Detail>

</Message>

</Messages>

</MicExportResponseMessage>

To Output all the inpit xml see here use the xsl:

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

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://service.aes.cust.mic.at">

<xsl:template match="node()|@*">

<xsl:copy>

<xsl:apply-templates select="@*|node()"/>

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

It looks like you are trying to extract the xml from a syschronous call response, the xsl above may bot be the entire solution but a atarting point at least to extract data, tags included .. you can eaisly test this in a xsl tool such as xml spy (there is a trial version) ..

Former Member
0 Kudos

Thanks!

I also made it to work with this xsl

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

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://service.aes.cust.mic.at">

<xsl:output method="xml" omit-xml-declaration="yes" />

<xsl:template match="/">

<xsl:for-each select="//m:sendDataReturn">

<xsl:value-of select="." disable-output-escaping="yes"/>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

Answers (1)

Answers (1)

henrique_pinto
Active Contributor
0 Kudos

Hi Brian,

it is mostly right.

You just forgot the namespace (notice that in your input XML the namespace is set, it's just that it is set to the default (empty) prefix).

The XSLT would be then:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://service.aes.cust.mic.at">
<xsl:template match="/">
<xsl:for-each select="//ns0:sendDataReturn">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Regards,

Henrique.