Author |
Message
|
Lebowski |
Posted: Wed Jun 14, 2017 4:04 am Post subject: Problem assigning namespace prefix |
|
|
Newbie
Joined: 26 May 2016 Posts: 7
|
Hi all,
I'm having an issue with assigning a namespace prefix. The external company that is to receive this message is expecting a specific prefix rather than the default [ns1] that is sent.
I've been banging my head off a wall trying to work this out, wonder if anybody has any suggestions? The code is below.
DECLARE XF NAMESPACE 'www.mynamespace.com';
SET Outputroot.XMLNSC.xmlexample.{ns1}:element = Inputroot.XMLNSC.xmlexample.element
so it should go like -
Input message
<xmlexample>
<element>value<element>
</xmlexample>
Output message
<xmlexample>
<XF:element>value<XF:element>
</xmlexample>
Instead the message is being output as -
<xmlexample>
<NS1:element xmlns:NS1="www.mynamespace.com">0100</NS1:element>>
</xmlexample>
I haven't much experience dealing with namespaces so the answer may be glaringly obvious.
Last edited by Lebowski on Wed Jun 14, 2017 4:53 am; edited 2 times in total |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jun 14, 2017 4:25 am Post subject: Re: Problem assigning namespace prefix |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Lebowski wrote: |
Hi all,
I'm having an issue with assigning a namespace prefix. The external company that is to receive this message is expecting a specific prefix rather than the default [ns1] that is sent.
I've been banging my head off a wall trying to work this out, wonder if anybody has any suggestions? The code is below.
DECLARE XF NAMESPACE 'www.mynamespace.com';
SET Outputroot.XMLNSC.xmlexample.{ns1}:element = Inputroot.XMLNSC.exampleelement
I haven't much experience dealing with namespaces so the answer may be glaringly obvious. |
If you want a namespace to have a specific prefix you need to insert the correspondant namespace declaration in the message tree.
From memory so you may want to check against the infocenter...
Code: |
DECLARE xf NAMESPACE 'www.mynamespace.com';
-- introducing the namespace decl into the tree to output all xf as prefix xf
SET OutputRoot.XMLNSC.xmlexample.(XMLNSC.NamspaceDecl)xmlns:xf='www.mynamespace.com';
-- usual element assignment with namespace (from declare namespace)
SET OutputRoot.XMLNS.xmlexample.xf:element1 = somevalue; |
Hope it helps  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Lebowski |
Posted: Wed Jun 14, 2017 4:55 am Post subject: Re: Problem assigning namespace prefix |
|
|
Newbie
Joined: 26 May 2016 Posts: 7
|
fjb_saper wrote: |
If you want a namespace to have a specific prefix you need to insert the correspondant namespace declaration in the message tree.
From memory so you may want to check against the infocenter...
Code: |
DECLARE xf NAMESPACE 'www.mynamespace.com';
-- introducing the namespace decl into the tree to output all xf as prefix xf
SET OutputRoot.XMLNSC.xmlexample.(XMLNSC.NamspaceDecl)xmlns:xf='www.mynamespace.com';
-- usual element assignment with namespace (from declare namespace)
SET OutputRoot.XMLNS.xmlexample.xf:element1 = somevalue; |
Hope it helps  |
I wasn't quite clear in my original message, I made an edit to show the output I'm getting and what my expected output should be. Can't seem to see where my syntax is wrong. Thanks for the help  |
|
Back to top |
|
 |
Vitor |
Posted: Wed Jun 14, 2017 4:57 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Also (and understand this may be nothing to do with your issue) your original code has braces "{}" not brackets "()".
Braces mean something to ESQL, and something different than brackets, which can give unexpected results.
My memory lines up with that of my worthy associate in terms of the code he posted, but it's still worth checking.
His advice is spot on. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jun 14, 2017 9:20 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You see the NS1 namespace being declared in the output. There should be no difference for a machine.
However if you want this to be a named namespace instead of a generated one (NSx) you need to add the namespace declaration into the message tree.
Program wise it is not needed beyond what you showed in your code.
But it is needed to name the output instead of showing a generated name in the output....
So
Code: |
DECLARE XF NAMESPACE 'www.mynamespace.com';
SET Outputroot.XMLNSC.xmlexample.XF:element = Inputroot.XMLNSC.exampleelement |
produces
Code: |
<xmlexample>
<NS1:element xmlns:NS1="www.mynamespace.com">0100</NS1:element>>
</xmlexample> |
but
Code: |
DECLARE xf NAMESPACE 'www.mynamespace.com';
-- introducing the namespace decl into the tree to output all xf as prefix xf
SET OutputRoot.XMLNSC.xmlexample.xf:element.(XMLNSC.NamspaceDecl)xmlns:XF='www.mynamespace.com';
-- usual element assignment with namespace (from declare namespace)
SET OutputRoot.XMLNS.xmlexample.xf:element1 = '0100'; |
Produces
Code: |
<xmlexample>
<XF:element xmlns:XF="www.mynamespace.com">0100<XF:element>
</xmlexample> |
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
joebuckeye |
Posted: Wed Jun 14, 2017 11:08 am Post subject: Re: Problem assigning namespace prefix |
|
|
 Partisan
Joined: 24 Aug 2007 Posts: 365 Location: Columbus, OH
|
Lebowski wrote: |
The external company that is to receive this message is expecting a specific prefix rather than the default [ns1] that is sent. |
This is a red flag. Probably means that the external company is doing string parsing of the message and not a compliant XML parser. Namespace prefixes are just a placeholder and do not change the logical meaning of a document.
Code: |
<xmlexample>
<XF:element>value<XF:element>
</xmlexample>
|
This is not valid XML. XF is not defined anywhere.
Code: |
<xmlexample>
<NS1:element xmlns:NS1="www.mynamespace.com">0100</NS1:element>
</xmlexample> |
This is valid XML because your namespace has been defined. Since you didn't define your namespace in the message the broker added a default prefix (NS1) to your outgoing message to make it valid (since you assigned a namespace to element in your code).
What fjb_saper is trying to get you to do is to define the namespace prefix yourself to match the silly requirement from the external vendor. You will have to add the namespace declaration line to your code if you want to control the prefix in your output message. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Jun 14, 2017 11:46 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You also need to remember that with the XMLNSC parser, you need to explicitly set the namespace (and not the namespace prefix) on every element that belongs to that namespace. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
|