cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove prefix "ns1" from XML tag ?

Former Member
0 Kudos

Hi all,

the payload I am sending to an HTTP site looks like this :

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

- <ns1:Order xmlns:ns1="rrn:org.xcbl:schemas/xcbl/v3_5/xcbl35.xsd">

- <ns1:OrderHeader>

- <ns1:OrderNumber>

<ns1:BuyerOrderNumber>2000032962</ns1:BuyerOrderNumber>

</ns1:OrderNumber>

<ns1:OrderIssueDate>2005-10-18</ns1:OrderIssueDate>

</ns1:OrderHeader>

</ns1:Order>

I have no idea where this "ns1" prefix comes from, seems like it is added automatically by XI.

The problem is that the supplier is waiting for standard XCBL structure and does not recognize this added "ns1".

The response I get from the HTTP server contains the following error :

<?xml version="1.0" encoding="UTF-8"?> <Values version="2.0"> <value name="$errorDump">Server error occurred</value> <record name="$errorInfo" javaclass="com.wm.util.Values"> <value name="$errorDump">Server error occurred</value> <value name="$error">[ISC.0042.9328] Error: namespace prefix ns1 not defined for element Order</value>

Thank you in advance.

Regards,

Julien

Accepted Solutions (1)

Accepted Solutions (1)

manish_bhalla2
Contributor
0 Kudos

Hi Julien,

In the Message Type, you have a entry for the XML namespace. Make sure that is empty.

However, if you are using an XSD provided by the supplier for the message, then you will have to write an xslt or java mapping program to remove the namespaces before you send it out of XI.

Cheers

Manish

Former Member
0 Kudos

Hi Manish,

I am using the file order.xsd form the XCBL 3.5 library (http://www.xcbl.org) as an imported archive and I can't find a place where an XML namespace is added.

Do you think I have to write a java or XSL mapping just to remove a prefix added by XI ??

Cheers,

Julien

Former Member
0 Kudos

Julien,

The namespace is picked up from the targetnamespace declaration in order.xsd.

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="rrn:org.xcbl:schemas/xcbl/v3_5/xcbl35.xsd" targetNamespace="rrn:org.xcbl:schemas/xcbl/v3_5/xcbl35.xsd" elementFormDefault="qualified">

One way of getting around this problem is to remove the targetNamespace declaration in order.xsd and all the included xsds (like orderheader.xsd) and reimporting the xsds into the repository.

Regards,

Suresh.

Former Member
0 Kudos

Hi Julien,

It would be handy to know mor about how this payload is being constructed, as this would give more info as to where the prefix is being set. But besides that, the document you are getting is as valid as any other. The namespace of the document is set by the namepsace URI, not the prefix. This can be set via the default namespace (xmlns="myNamespaceURI") or a prefix (xmlns:xyz="myNamespaceURI"). The prefix is purely a

shorthand representation for the URI, which is the true identifier of the namespace.

So the element "OrderNumber" would be in the namespace "myNamespaceURI" whether it is defined as:

<OrderNumber xmlns="myNamespaceURI">

or

<xyz:OrderNumber xmlns:xyz="myNamespaceURI">

As they are simply 2 ways of saying exactly the same thing. The first uses the default namespace and the second uses a prefix tied to the same namespace through

an appropriate declaration.

So the reciever of this doc should not strictly be failing it, as it is valid. But that probably does not help you much! If you can't get them to configure WebMethods (or BC?) to accept this prefix (this can be done using an "nsDecls" record) then you could either alter whatever is generating your payload to use the default namespace, or pass it through a simple stylesheet to change the instance to use a default namespace tied to the targetNamespace.

Chris

Former Member
0 Kudos

Hi Suresh and Chris,

thank you for answering.

Suresh,

>The namespace is picked up from the targetnamespace declaration in order.xsd.

I checked the XCBL file order.xsd, there is no trace of "ns0" or "ns1" in it.

I think this "ns" prefix is set by XI at mapping time : when I design the mapping between the BAPI request structure (source) and order.xsd (target), if I check the "Source text" view in tab "design", there are no prefixes. But when I go to the "test" tab, in the "Source text" view, I can see that the prefix "ns0" has been added in the source message, and "ns1" in the target message.

Unfortunately I can't find any parameter in the message mapping object saying something like "do not add prefix"...

Julien

Former Member
0 Kudos

Hi Julien,

Chris is absolutely correct.

Obviously, the XSD you use to define your Message Mapping states that all elements should be namespace qualified (probably by defining elementDefault="qualified").

As Chris pointed out there are several ways of expressing this namespace qualification which are all logically equivalent. A receiver should treat all these logically equivalent representations identically. For this reason the Message Mapping does not provide a possibility to configure which way is used.

If your special receiver does not behave this way I would first consider it his fault. But maybe you are not able to convince him about this. In this case I fear you have to use a java or xslt mapping in order to produce the style your receiver expects.

Greetings

Stephan

Former Member
0 Kudos

Hi Stephan,

thank you to you and Chris for your very clear answers.

I never did neither XSLT nor java mapping before. What tools would tou advice to use for this ?

Julien

Former Member
0 Kudos

try this...

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

xmlns="rrn:org.xcbl:schemas/xcbl/v3_5/xcbl35.xsd"

version="1.0">

<xsl:output method="xml"/>

<xsl:template match="/">

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

</xsl:template>

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

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

<xsl:element name="{$newname}">

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

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

</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>

Former Member
0 Kudos

Hi Chris,

It works !

Thanks a lot !

May I ask you how you wrote it (documentation ? which tool ?) ?

Julien

PS : Sorry I can't give you the "Solved my problem" points because this problem is supposed to be already solved

Former Member
0 Kudos

Hi Julien

There are a lot tools available to help you in writing XSLT like,

Stylus Studio - www.stylusstudio.com

XMLSpy - www.altova.com

Xselerator - www.marrowsoft.com etc.

You can learn XSL at www.w3schools.com/xsl/

It is pretty easy.

cheers

Sameer

Former Member
0 Kudos

Thank you Sameer, this site looks great.

I already tried XMLSpy : a lot of functionnalities (maybe too much for a non-XML expert) but it's not free...

I'll have a look at the 2 others web site.

Julien

Former Member
0 Kudos

Julien

Glad it worked. As for which tools and how, Textpad and I actually already had it, just modified slightly for your situation (I have the unfair advantage of having a few years working with xslt, and xCBL specifically - this issue came up a fair amount).

As for learning xslt, I agree whole-heartedly with Sameer, but would also recommend zvon.org and the XSLT Quick Reference from mulberrytech (www.mulberrytech.com/quickref/XSLTquickref.pdf). I like to keep a copy of it handy.

Chris

Former Member
0 Kudos

Hi Julien

Well if you want a free xsl editor, there is one available called as cooktop, you can download it at,

http://www.tucows.com/preview/350904.html

It is a very simple xsl editor, with not as many features as stylus or xmlspy. But it is pretty good and best of all free

And Chris thanks for recommending couple of other sites.

cheers

Sameer

Answers (0)