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 » Changing namespaces during runtime ?

Post new topic  Reply to topic
 Changing namespaces during runtime ? « View previous topic :: View next topic » 
Author Message
my_mqmb
PostPosted: Mon Jun 16, 2014 2:27 am    Post subject: Changing namespaces during runtime ? Reply with quote

Voyager

Joined: 08 Jun 2011
Posts: 84

I want to change the namespace prefix in a line of esql code dynamically based on some condition.

for eg :

Code:


DECLARE top1 NAMESPACE 'http://lto.com/dis/schemas/issuerinterface1.0';
        
DECLARE top NAMESPACE  'InterfaceServiceV1.0.4';   


-- sometimes i want my output to go like --

SET OutputRoot.XMLNSC.top:createRequest.requestUID=        Environment.Variables.RqstUID ;

 -- and sometimes  the output to go like --

SET OutputRoot.XMLNSC.top1:createRequest.requestUID=           Environment.Variables.RqstUID ;




based on a condition how can i switch top or top1 and make the xmlnsc parser switch the prefixes .
Back to top
View user's profile Send private message
Esa
PostPosted: Mon Jun 16, 2014 2:50 am    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

A prefix is just a shorthand. In fact you need to change the namespace. The prefix will follow, if you have added the namespace declaration. Otherwise you get a prefix like 'NS1'.

Code:
SET OutputRoot.XMLNSC.top1:createRequest.requestUID=           Environment.Variables.RqstUID ;

SET OutputRoot.XMLNSC.top1:createRequest NAMESPACE = top;
Back to top
View user's profile Send private message
my_mqmb
PostPosted: Mon Jun 16, 2014 3:21 am    Post subject: Reply with quote

Voyager

Joined: 08 Jun 2011
Posts: 84

I thing i dint explain properly .

say that i have 100 lines of code .

Based on some condition i need to just switch to other namespace in the output . so i dont want to make it 200 lines of code.


i need my esql to select between top and top1 dynamically ..

something like
IF condition
SET dynamic = top ;
ELSE
SET dynamic = top1 ;
END iF;

SET outputroot.XMLNSC.{dynamic}:createRequest.requestUID



How to achieve something like above ?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Jun 16, 2014 4:46 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20697
Location: LI,NY

my_mqmb wrote:
I thing i dint explain properly .

say that i have 100 lines of code .

Based on some condition i need to just switch to other namespace in the output . so i dont want to make it 200 lines of code.


i need my esql to select between top and top1 dynamically ..

something like
IF condition
SET dynamic = top ;
ELSE
SET dynamic = top1 ;
END iF;

SET outputroot.XMLNSC.{dynamic}:createRequest.requestUID



How to achieve something like above ?


So how about
Code:
DECLARE top1 NAMESPACE 'http://lto.com/dis/schemas/issuerinterface1.0';
         
DECLARE top NAMESPACE  'urn:InterfaceServiceV1.0.4'; 

DECLARE dynamic NAMESPACE  top1;

IF condition
SET dynamic = top ;
ELSE
SET dynamic = top1 ;
END iF;

SET outputroot.XMLNSC.{dynamic}:createRequest.requestUID


Have you tried this and did it work?
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Esa
PostPosted: Mon Jun 16, 2014 4:58 am    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

fjb_saper wrote:

So how about
Code:
DECLARE top1 NAMESPACE 'http://lto.com/dis/schemas/issuerinterface1.0';
         
DECLARE top NAMESPACE  'urn:InterfaceServiceV1.0.4'; 

DECLARE dynamic NAMESPACE  top1;

IF condition
SET dynamic = top ;
ELSE
SET dynamic = top1 ;
END iF;

SET outputroot.XMLNSC.{dynamic}:createRequest.requestUID


Have you tried this and did it work?


If it doesn't work, replace the last line with this and test again:

Code:
SET OutputRoot.XMLNSC.dynamic:createRequest.requestUID


And it's not the spelling of OutputRoot that is the point, but the omission of curly braces.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Jun 16, 2014 5:09 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20697
Location: LI,NY

Esa wrote:

And it's not the spelling of OutputRoot that is the point, but the omission of curly braces.




That'll teach me to check after cut and paste
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
my_mqmb
PostPosted: Mon Jun 16, 2014 6:17 am    Post subject: Reply with quote

Voyager

Joined: 08 Jun 2011
Posts: 84

[quote="fjb_saper"]
Esa wrote:

And it's not the spelling of OutputRoot that is the point, but the omission of curly braces.


My code output :

<NS1:createRequest xmlns:NS1="dex1"> <requestUID>66</requestUID></NS1:createRequest>


Suggested code output :


<NS1:createRequest xmlns:NS1="ReqNamespace"> <requestUID>66</requestUID></NS1:createRequest>


What i need :

<NS1:createRequest><requestUID>66</requestUID></NS1:createRequest>


where NS1 ( sent by broker) has either http://lto.com/dis/schemas/issuerinterface1.0 ( top1) or InterfaceServiceV1.0.4 (top)


i dont need the attribute data.
Back to top
View user's profile Send private message
Esa
PostPosted: Mon Jun 16, 2014 6:47 am    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

my_mqmb wrote:


i dont need the attribute data.


If you by "attribute data" mean XML declarations, you do need them. If you don't create them yourself where you want them to be placed, the parser will generate them where it thinks is the proper place.

Search this forum for "DoubleNamespaceDeclaration".
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Jun 16, 2014 7:28 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20697
Location: LI,NY

Esa wrote:
my_mqmb wrote:


i dont need the attribute data.


If you by "attribute data" mean XML declarations, you do need them. If you don't create them yourself where you want them to be placed, the parser will generate them where it thinks is the proper place.

Search this forum for "DoubleNamespaceDeclaration".


And if you don't create the xml namespace declaration in your output tree, the broker may decide to give a different namespace prefix to every occurrence, with the corresponding namespace declaration (exemple xsi:nil = "true").
If xsi has not been declared (xml namespace declaration) the broker will create a different namespace prefix for each occurrence of xsi...

So better remember your xml namespace declarations in your documents at the start of the document... You can still do them once you are done creating the message tree... Just add it to the finished message tree at the appropriate level ... preferably as first child?

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
kimbert
PostPosted: Mon Jun 16, 2014 7:43 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

I think it's time to summarize the problem and the solution. Thanks go to mgk for providing the answer.

Requirement: In an ESQL field reference, use a variable where the namespace constant usually appears.
Example:
Code:
Set OutputRoot.XMLNSC.nsA_or_nsB:root.field1 = '';
where 'prefixAorPrefixB' has been initialised to point to either of two alternative namespaces.

Solution:
- Declare both NAMESPACE constants in the usual way
- Declare a CHARACTER variable '
- SET the CHARACTER variable from either of the two NAMESPACE constants.
- In the field reference, use the CHARACTER variable in {} to specify the namespace.

Code:
DECLARE top1 NAMESPACE 'http://lto.com/dis/schemas/issuerinterface1.0';
DECLARE top NAMESPACE  'urn:InterfaceServiceV1.0.4'; 
DECLARE dynamic CHARACTER;

IF condition
    SET dynamic = top;
ELSE
    SET dynamic = top1 ;
END IF;

SET Outputroot.XMLNSC.{dynamic}:createRequest.requestUID

_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
Esa
PostPosted: Mon Jun 16, 2014 11:37 pm    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

Interesting to see that you can handle namespaces as if they were CHAR variables.

This works, too:
Code:
DECLARE top1 NAMESPACE 'http://lto.com/dis/schemas/issuerinterface1.0';
DECLARE top NAMESPACE  'urn:InterfaceServiceV1.0.4';
DECLARE dynamic CHARACTER;

IF condition
    SET dynamic = top;
ELSE
    SET dynamic = top1 ;
END IF;
      
DECLARE outRef REFERENCE TO OutputRoot;
CREATE LASTCHILD OF outRef AS outRef DOMAIN('XMLNSC');
CREATE LASTCHILD OF outRef.XMLNSC AS outRef NAMESPACE dynamic NAME 'createRequest';
SET outRef.requestUID = <something>;


if you prefer to build the output message using reference variables.
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 » Changing namespaces during runtime ?
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.