cancel
Showing results for 
Search instead for 
Did you mean: 

XML Namespace Prefix Lost

Former Member
0 Kudos

I am working on a RFC to JMS scenario and am having trouble getting the XML in the required format. I have loaded the XML file provided in my mapping. However the result was not what I had anticipated.

<br>

This is the XML provided and what I want to produce:

<br>

<

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

<MyNS3:Maint_Struc <br>

xmlns:MyNS1="http://www.MyTest.com/My_Namespace/Part1" <br>

xmlns:MyNS2="http://www.MyTest.com/My_Namespace/Part2" <br>

xmlns:MyNS5="http://www.MyTest.com/My_Namespace/Part5" <br>

xmlns:MyNS3="http://www.MyTest.com/My_Namespace/Part3" <br>

xmlns:MyNS4="http://www.MyTest.com/My_Namespace/Part4" <br>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <br>

xsi:schemaLocation="www.MyTest.com/My_Namespace/Part3 file:/C:/MyStructure.xsd">

<br>

<

MyNS2:SubStruc_1> <br>

<

MyNS2:Fld_1_1_A>Value001<

/MyNS2:Fld_1_1_A> <br>

<

MyNS2:Fld_1_1_B>Value002<

/MyNS2:Fld_1_1_B> <br>

<

/MyNS2:SubStruc_1> <br>

<br>

<

MyNS3:SubStruc_2> <br>

<

MyNS1:SubStruc_2_1> <br>

<

MyNS1:Fld_2_1_A>Value003<

/MyNS1:Fld_2_1_A> <br>

<

MyNS1:Fld_2_1_B>Value004<

/MyNS1:Fld_2_1_B> <br>

<

/MyNS1:SubStruc_2_1> <br>

<

MyNS4:Fld_2_A>Value005<

/MyNS4:Fld_2_A> <br>

<

MyNS4:Fld_2_B>Value006<

/MyNS4:Fld_2_B> <br>

<

/MyNS3:SubStruc_2> <br>

<br>

<

MyNS3:SubStruc_3> <br>

<

MyNS5:SubStruc_3_1> <br>

<

MyNS5:Fld_3_1_A>Value007<

/MyNS5:Fld_3_1_A> <br>

<

MyNS5:Fld_3_1_B>Value008<

/MyNS5:Fld_3_1_B> <br>

<

/MyNS5:SubStruc_3_1> <br>

<

MyNS3:Fld_3_A>Value009<

/MyNS3:Fld_3_A> <br>

<

MyNS5:Fld_3_B>Value010<

/MyNS5:Fld_3_B> <br>

<

MyNS2:Fld_3_C>Value011<

/MyNS2:Fld_3_C> <br>

<

/MyNS3:SubStruc_3> <br>

<

/MyNS3:Maint_Struc> <br>

<br>

However I am getting the following when mapped: <br>

<

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

<

ns0:Maint_Struc <br>

xmlns:MyNS4="http://www.MyTest.com/My_Namespace/Part4" <br>

xmlns:MyNS5="http://www.MyTest.com/My_Namespace/Part5" <br>

xmlns:MyNS2="http://www.MyTest.com/My_Namespace/Part2" <br>

xmlns:MyNS1="http://www.MyTest.com/My_Namespace/Part1" <br>

xmlns:ns0="http://www.MyTest.com/My_Namespace/Part3" <br>

xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance" <br>

ns1:schemaLocation="www.MyTest.com/My_Namespace/Part3 file:/C:/MyStructure.xsd"> <br>

<

ns2:SubStruc_1 xmlns:ns2="http://www.MyTest.com/My_Namespace/Part2"> <br>

<

ns2:Fld_1_1_A>Value001<

/ns2:Fld_1_1_A> <br>

<

ns2:Fld_1_1_B>Value002<

/ns2:Fld_1_1_B> <br>

<

/ns2:SubStruc_1> <br>

<br>

<

ns0:SubStruc_2> <br>

<

ns3:SubStruc_2_1 xmlns:ns3="http://www.MyTest.com/My_Namespace/Part1"> <br>

<

ns3:Fld_2_1_A>Value003<

/ns3:Fld_2_1_A> <br>

<

ns3:Fld_2_1_B>Value004<

/ns3:Fld_2_1_B> <br>

<

/ns3:SubStruc_2_1> <br>

<

ns4:Fld_2_A xmlns:ns4="http://www.MyTest.com/My_Namespace/Part4">Value005<

/ns4:Fld_2_A> <br>

<

ns4:Fld_2_B xmlns:ns4="http://www.MyTest.com/My_Namespace/Part4">Value006<

/ns4:Fld_2_B> <br>

<

/ns0:SubStruc_2> <br>

<br>

<

ns0:SubStruc_3> <br>

<

ns5:SubStruc_3_1 xmlns:ns5="http://www.MyTest.com/My_Namespace/Part5"> <br>

<

ns5:Fld_3_1_A>Value007<

/ns5:Fld_3_1_A> <br>

<

ns5:Fld_3_1_B>Value008<

/ns5:Fld_3_1_B> <br>

<

/ns5:SubStruc_3_1> <br>

<

ns0:Fld_3_A>Value009<

/ns0:Fld_3_A> <br>

<

ns5:Fld_3_B xmlns:ns5="http://www.MyTest.com/My_Namespace/Part5">Value010<

/ns5:Fld_3_B> <br>

<

ns2:Fld_3_C xmlns:ns2="http://www.MyTest.com/My_Namespace/Part2">Value011<

/ns2:Fld_3_C> <br>

<

/ns0:SubStruc_3> <br>

<

/ns0:Maint_Struc> <br>

<br>

Things that are wrong with the mapped XML: <br>

- the namespace "http://www.MyTest.com/My_Namespace/Part3" was prefixed with MyNS3 but XI reassigned it to ns0

<br>- original prefixes are not used in the element tags <br>

<br>

Appreciate if anyone can help. <br>

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

former_member200962
Active Contributor
0 Kudos

If you want to keep the original namespace prefixes then try the use of XSLT mapping

In XSLT you can specify the prefix which needs to be associated with the corresponding namespace...you need to ensure that the same relation is maintained throughout the mapping......

Regards,

Abhishek.

Answers (3)

Answers (3)

Former Member
0 Kudos

Thank You All.

Former Member
0 Kudos

Thank you for all your valuable suggestions. Does any know why XI/PI does not acknowledge/use the namespace prefix that is defined in the XML? Is there no other way around this short-coming apart from using XSLT mapping?

<br>

I did try using the anonymizer (as suggested by Manjusha). With the anonymizer I am able to change the namespace prefix in the element tags to the way I want it. However the namespace definition is still showing in the element tag.

<br>

<MyNS2:SubStruc_1 xmlns:MyNS2="http://www.MyTest.com/My_Namespace/Part2"> <br>

<MyNS2:Fld_1_1_A>Value001</MyNS2:Fld_1_1_A> <br>

<MyNS2:Fld_1_1_B>Value002</MyNS2:Fld_1_1_B> <br>

</MyNS2:SubStruc_1> <br>

<br>

This is almost perfect only if I am able to remove the definition xmlns:MyNS2="http://www.MyTest.com/My_Namespace/Part2" from the element tag. Suggestion any one?

Thanks All.

Former Member
0 Kudos

Well You can try to use a java mapping.

stefan_grube
Active Contributor
0 Kudos

> Does any know why XI/PI does not acknowledge/use the namespace prefix that is defined in the XML?

Because namespace prefixes can be choosed freely. It is no difference, what prefix is used. The XML document is semantically equal.

It the receiver requests a fixed namespace, then the parser of the receiver behaves wrong.

Regards

Stefan

Former Member
0 Kudos

Please check if this helps:

/people/stefan.grube/blog/2007/02/02/remove-namespace-prefix-or-change-xml-encoding-with-the-xmlanonymizerbean

Regards,

Manjusha.

Former Member
0 Kudos

Hi,

The best way to get the namespace prefix u want is, by using the XSLT mapping.

In XSLT mapping u can specify the prefix u want to be prefixed directly.

Also u can use SAX parser or DOM parser to do the same....

I hope this will answer your question

Former Member
0 Kudos

hi. peppa

I agree with guys , you need to use an XSLT , XI always asigned the prefix ns0 , ns1...etc.

So if you need to change your prefix use an XSLT.

Please check the links.

One more site where you can get all the XSLT-related information:

http://www.w3schools.com/xsl/default.asp