ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Problem assigning namespace prefix

Post new topic  Reply to topic
 Problem assigning namespace prefix « View previous topic :: View next topic » 
Author Message
Lebowski
PostPosted: Wed Jun 14, 2017 4:04 am    Post subject: Problem assigning namespace prefix Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Wed Jun 14, 2017 4:25 am    Post subject: Re: Problem assigning namespace prefix Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
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
View user's profile Send private message Send e-mail
Lebowski
PostPosted: Wed Jun 14, 2017 4:55 am    Post subject: Re: Problem assigning namespace prefix Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Wed Jun 14, 2017 4:57 am    Post subject: Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Wed Jun 14, 2017 9:20 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
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
View user's profile Send private message Send e-mail
joebuckeye
PostPosted: Wed Jun 14, 2017 11:08 am    Post subject: Re: Problem assigning namespace prefix Reply with quote

Partisan

Joined: 24 Aug 2007
Posts: 364
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
View user's profile Send private message
mqjeff
PostPosted: Wed Jun 14, 2017 11:46 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Problem assigning namespace prefix
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.