cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to add xml namespace tag

Former Member
0 Kudos

Hi,

I am doing file to idoc scenario and my requirement is as below:

XML file which i am getting is not having <ns> namespace tag and when i pass this file to PI it gives error due to namespace is missing.

Can anyone send UDF to add namespace tag in xml structure? Below is the xml structure actual and required.

Actual structure

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

<Extracteur>

<Territoire>DL</Territoire>

<Inquiry>

<no_ina>86</no_ina>

<no_str>D1</no_str>

</Inquiry>

</Extracteur>

Required Structure

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

<ns0:MT_File xmlns:ns0="um:sap.com">

<Extracteur>

<Territoire>DL</Territoire>

<Inquiry>

<no_ina>86</no_ina>

<no_str>D1</no_str>

</Inquiry>

</Extracteur>

</ns0:MT_File>

Thanks

Kunal

View Entire Topic
markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

Sorry, I have had the wrong interpretation of your question. Basically, you need to modify the xml message and add the namespaces manually when you are testing. You can do this by:

1. Editing your xml using notepad

2. Add the tag <ns0:MT_File xmlns:ns0="um:sap.com"> just after <?xml version="1.0" encoding="UTF-8"?>

3. Add the tag </ns0:MT_File> at the end of the message

4. Save your file with an .xml extension

When in runtime, you do not need to add the tags since XI/PI will remove them. It will recognize the real structure.

Regards,

Former Member
0 Kudos

When in runtime, you do not need to add the tags since XI/PI will remove them. It will recognize the real structure.

Actually PI should recognize the real structure regardless of namespace because third party (File Sender) is not suppose to know the namespace used in PI. But it is not doing the same.

When i execute my scenario without giving namespace in payload, PI doesn,t except the payload without namespace.

Any Suggestions

aashish_sinha
Active Contributor
0 Kudos

Hi,

In mapping, just try to concatenate the namespace after the count of first line. Lets say if first line has 100 words add namespace after that. You can do it using mapping also. Try concat function.

You can write an UDF.

UDF logic :

inside loop

Count the number of letters until it find one 'nl'; new line

if new line found

concat namespace after that no of count including 'nl' and then again concatnate 'nl' in last

break;

else

do nothing

end loop

Hope this will clarify.

You can also replace first line with addition of firstline and namespace.

regards

Aashish Sinha

Former Member
0 Kudos

Hi,

I m new to java and already know this logic but i dont know how to write the code to meet the above requirement.

Can anyone paste the code here to add namespace tag in xml message?

Thanks

Kunal

stefan_grube
Active Contributor
0 Kudos

Use this XSLT mapping as first mapping step (before the graphical mapping):

<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>

<xsl:template match="/">

<ns0:MT_File xmlns:ns0="um:sap.com">

  <xsl:copy-of select="." /> 

</ns0:MT_File>

</xsl:template>
</xsl:stylesheet>

Regards

Stefan

sbhutani1
Contributor
0 Kudos

Hi Stefan,

Thanks for this XSL code, it solved my problem. Could you also suggest on how to remove the doctype declaration on second line of xml document.

<!DOCTYPE XmlExtracteur SYSTEM "XmlExtracteur.dtd">

Thanks

stefan_grube
Active Contributor
0 Kudos

When you have a dtd file, you could upload this as external definition and create an interface based on that. So you would need no pre-mapping.

Regards

Stefan

henrique_pinto
Active Contributor
0 Kudos

Actually PI should recognize the real structure regardless of namespace because third party (File Sender) is not suppose to know the namespace used in PI. But it is not doing the same.

Not true at all!

The namespace is as important for the XML message structure as the tags names themselves!

So, if you define the structure within XI, you need to export the WSDL (in case of soap/web service) or XSD (in case of file, mail, http etc) and send it to the consumer of the interface, so that they create the message exactly like the service provider expects it. That's the best practice for cross-component/company integration.

On the other hand, if the message was already defined in the sender system, you'll need to import its definition (WSDL/XSD) in XI and develop the interface over it.

Nevertheless, it would always be possible to just:

1. change your data/message type to exclude the unecessary root tag.

2. leave the XML Namespace field of the message type as blank.

Regards,

Henrique.

Former Member
0 Kudos

>

> When you have a dtd file, you could upload this as external definition and create an interface based on that. So you would need no pre-mapping.

>

I am also facing same problem but dont have the dtd file. Is there any other way to remove dtd declaration?