cancel
Showing results for 
Search instead for 
Did you mean: 

java messgae mapping help pls

Former Member
0 Kudos

hi forum, in message mapping, when i see the XML of the target or source structure i can see the prefix of the qualifiedNameas as ns1 or ns0,

eg., <ns0:MT_sdptest_JMapTest2>

what does that signify....

coz when i made a java mapping programm and tried to test it as an independant program outside XI, taking one XML file as input and one XML file as output, in the code for creating the output structure, i hade created the root element(for the output structure) as

Element rootNode = documentOut.createElementNS("http://zpoc.com.test/sdptest","ns0:MT_sdptest_JMapTest2");

the XML produced gives error as:

"Reference to undeclared namespace prefix: 'ns0'. Error processing resource "

pls help me.....coz i want to intergrate it in a Interface mapping in a scenario

Accepted Solutions (1)

Accepted Solutions (1)

paul_digance
Explorer
0 Kudos

You can remove the namespace prefixes using an XSLT mapping if they are causing problems with applications outside of XI.

Try the following code:

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

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns="http://www.arconw.com/XI/XSLT_Library/XmlNamespacePrefixRemoval"

version="1.0">

<xsl:output method = "xml" />

<xsl:template match="/">

<xsl:apply-templates select="*" mode="remprefix"/>

</xsl:template>

<xsl:template match="*" mode="remprefix">

<xsl:variable name="newname" select="local-name(.)"/>

<xsl:element name="{$newname}" namespace ="{namespace-uri()}">

<xsl:apply-templates mode="copyall" select="@*|comment()|processing-instruction()|text()"/>

<xsl:apply-templates select="*" mode="remprefix"/>

</xsl:element>

</xsl:template>

<xsl:template mode="copyall" match="@*|comment()|processing-instruction()|text()">

<xsl:copy>

<xsl:apply-templates mode="copyall" select="@*|comment()|processing-instruction()|text()"/>

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

      • Please assign forum points if you find this useful ***

Thanks,

Paul D.

Message was edited by:

Paul Digance

Answers (7)

Answers (7)

Former Member
0 Kudos

thanks

Former Member
0 Kudos

Pankaj,

Have you seen this weblog:

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

---Satish

henrique_pinto
Active Contributor
0 Kudos

You dont need to set the exactly same prefix as XI. Just use it without any prefix:

...
docOutput.createElementNS("http://zpoc.com.test/sdptest","MT_sdptest_JMapTest2");
...

Regards,

Henrique.

Former Member
0 Kudos

Hi,

Copy the XML into Altova XMLSpy -- mapforce ,and check the validity of xml

Regards

Chilla

Former Member
0 Kudos

Hi Pankaj,

The XML namespace attribute is placed in the start tag of an element and has the following syntax:

xmlns:namespace-prefix="namespaceURI"

<ns0: table xmlns:ns0="http://www.mystudy.com/furniture">

<ns0:name>Coffee Table</ns0:name>

<ns0:width>80</ns0:width>

<nns0:length>120</ns0:length>

</ns0:table>

When a namespace is defined in the start tag of an element, all child elements with the same prefix are associated with the same namespace. Here ns0 represents the namespace "http://www.mystudy.com/furniture".

Hope this gives you clarification regarding namespaces.

**Award points if useful

Cheers,

Santosh

Former Member
0 Kudos

thanks prabhu and Santosh...

santosh i understood what u said...but help in writing the java code...means

i want to create the root element as:

<ns0:MT_sdptest_JMapTest2 xmlns:ns0="URL/URN">

for this clarify the java statement....is it like this

Element rootNode =

documentOut.createElementNS("http://zpoc.com.test/sdptest","ns0:MT_sdptest_JMapTest2");

rectify this part of code...as this is erroneous

Former Member
0 Kudos

Pankaj,

Try This.

try to create the element firstly and set the attribute using setAttribute method

Element rootNode = docOutput.createElementNS("http://zpoc.com.test/sdptest","ns0:MT_sdptest_JMapTest2");

rootNode.setAttribute("xmlns:ns0", "http://zpoc.com.test/sdptest");

<b>Output is like:

<ns0:Table xmlns:ns0="http://www.w3.org/2001/XMLSchema"/></b>

Cheers,

Santosh

*Award Points if useful

Former Member
0 Kudos

santosh...thanks a lotttttttttttttttttt...

its great...can u pls explain me these two liones

<<<<<<Element rootNode = docOutput.createElementNS("http://zpoc.com.test/sdptest","ns0:MT_sdptest_JMapTest2");

rootNode.setAttribute("xmlns:ns0", "http://zpoc.com.test/sdptest");

>>>>>

means whats the meaning... why do i need to write the second line to setAttribute**

Former Member
0 Kudos

Hi Pankaj,

The second line adds an attribute to the element, which in our case is the name space.

so the namespace URI will be set as an attribute to the element "MT_sdptest_JMapTest2"

Hope this clarifies ...

Cheers,

Santosh

*Award Points if useful

Former Member
0 Kudos

Hi-

Check the namespace name in your XML file .

May be problem with your XML file,check all the syntax.

May be this will be helpful.

prabhu_s2
Active Contributor
0 Kudos

ur xml strucutre is not framed good....try to have <ns0:MT_sdptest_JMapTest2 xmlns:ns0="URL/URN"> and test it

Message was edited by:

Prabhu S

prabhu_s2
Active Contributor
0 Kudos

content deleted.

Message was edited by:

Prabhu S