cancel
Showing results for 
Search instead for 
Did you mean: 

Adding comment line in XML message

Former Member
0 Kudos

Hi,

Does anyone know how to add a comment line in outgoing XML message from XI? Using graphical mapping or java or adapter module?

Something like .....

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

<! this is a comment>

<record>

Thanks

Pushpinder

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You can write below statement in simple java mapping

As you want to insert comment before <record>

read entire source structure in string strXMLSource

finalString = strXMLSource.replaceAll("<record>", "<!-- this is a comment--><record>");

in out.write statement pass finalString....

No need to write any parser, just write simple code in execute method

Answers (4)

Answers (4)

jan_krohn
Active Participant
0 Kudos

You can transform your XML with an XSLT transformation:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output encoding="utf-8" indent="no" method="xml" version="1.0"/>

<xsl:param name="COMMENT"/>

<xsl:preserve-space elements="*"/>

<xsl:template match="/">

<xsl:comment>

<xsl:value-of select="$COMMENT"/>

</xsl:comment>

<xsl:copy>

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

</xsl:copy>

</xsl:template>

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

<xsl:copy>

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

</xsl:copy>

</xsl:template>

</xsl:transform>

Best wishes,

Jan

Former Member
0 Kudos

Some more complications in the requirement

Former Member
0 Kudos

Hi Pushpinder,

depends on the kind of mapping you process:

1) graphical mapping: not possible

2) xsl-mapping: use <xsl:comment>

3) JAVA-Mapping: Insert a comment-node to the target structure

3) ABAP-Mapping: Insert a comment-node to the target structure

Regards Mario

Former Member
0 Kudos

Thanks to all who replied!!

I am very near to the solution. In the comment I need to pick up the first tag of the xml dynamically.

Say in place of <record> it could be specific to interface, then how to do it?

Please help

Thanks

Pushpinder

Former Member
0 Kudos

Hi Pushpinder,

Can you explain exactly what you are looking for with one example. It can be very well done using Java Mapping.

Thanks

amit

Former Member
0 Kudos

Hi,

I have to add a comment line in the target xml like:

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

<!DOCTYPE RMS_MODEL SYSTEM 'RMS_Model.dtd'>

<RMS_MODEL>

<DIVISION Value="2"/>

<RMS_RANGE Value="0801"/>

<WORKING_NO Value="S8153219"/>

<MODEL_NO/>

<MODEL_NAME/>

<CARRY_OVER/>

i am able to achieve the above.

But in my message mapping I am using multi mapping, so after the message mapping the target structure looks something like:

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

<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge"><ns0:Message1>

<!DOCTYPE RMS_MODEL SYSTEM 'RMS_Model.dtd'>

<RMS_MODEL>

<DIVISION Value="2"/>

<RMS_RANGE Value="0801"/>

<WORKING_NO Value="S8153219"/>

<MODEL_NO/>

<MODEL_NAME/>

<CARRY_OVER/>

now, is it possible to add a comment line as shown in this example?Or is it preferable to use an adapter module?

Thanks

Pushpinder

Former Member
0 Kudos

Hey Pushpinder,

It should be possible without using a adapter module. Just give it a try and let me know. Don't worry about Messages and Message1.

amit

Former Member
0 Kudos

Hi Amit,

But it will make a difference as the messages will be split after the message mapping. So how java mapping going to handle it?

I have tried deploying the java code but it is not inserting the comment line in the final message.

Thanks

Pushpinder

sunil_singh13
Active Contributor
0 Kudos

Comment for xml should be inserted

<!-- Your Comment -->

Thanks

Sunil Singh