Author |
Message
|
my_mqmb |
Posted: Mon Jun 16, 2014 2:27 am Post subject: Changing namespaces during runtime ? |
|
|
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 |
|
 |
Esa |
Posted: Mon Jun 16, 2014 2:50 am Post subject: |
|
|
 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 |
|
 |
my_mqmb |
Posted: Mon Jun 16, 2014 3:21 am Post subject: |
|
|
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 |
|
 |
fjb_saper |
Posted: Mon Jun 16, 2014 4:46 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 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 |
|
 |
Esa |
Posted: Mon Jun 16, 2014 4:58 am Post subject: |
|
|
 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 |
|
 |
fjb_saper |
Posted: Mon Jun 16, 2014 5:09 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 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 |
|
 |
my_mqmb |
Posted: Mon Jun 16, 2014 6:17 am Post subject: |
|
|
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 |
|
 |
Esa |
Posted: Mon Jun 16, 2014 6:47 am Post subject: |
|
|
 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 |
|
 |
fjb_saper |
Posted: Mon Jun 16, 2014 7:28 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 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 |
|
 |
kimbert |
Posted: Mon Jun 16, 2014 7:43 am Post subject: |
|
|
 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 |
|
 |
Esa |
Posted: Mon Jun 16, 2014 11:37 pm Post subject: |
|
|
 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 |
|
 |
|