Author |
Message
|
bharadwaj |
Posted: Wed Dec 28, 2016 6:38 pm Post subject: Getting error while creating namespaces in XML |
|
|
Newbie
Joined: 28 Dec 2016 Posts: 2
|
i am trying to create the below xml using esql
<gesmes:Envelope xmlns:gesmes="namespace1" xmlns="namespace2">
<Cube>
<Cube time="2016-05-18">
<Cube currency="EUR" rate="4.4260" />
</Cube>
</Cube>
</gesmes:Envelope>
Following is my code in esql
DECLARE gesmes NAMESPACE 'namespace1';
DECLARE eurofxref NAMESPACE 'namespace2';
SET OutputRoot.XMLNSC.gesmes:Envelope.XMLNSC.NamespaceDecl)xmlns = eurofxref;
SET OutputRoot.XMLNSC.gesmes:Envelope.Cube.Cube.(XMLNSC.Attribute)time = InputRoot.XMLNSC.ExchangeRatesSeries.Rates.Rate.EffectiveDate;
SET OutputRoot.XMLNSC.gesmes:Envelope.Cube.Cube.(XMLNSC.Attribute)currency = InputRoot.XMLNSC.ExchangeRatesSeries.Code;
When i execute, I am getting error as
Element must have a namespace specified if there is a default namespace in scope
Also instead of gesmes I am getting ns1 in output i.e
<NS1:Envelope xmlns:NS1="namespace1" xmlns="namespace2">
Can anyone suggest where I am doing wrong please..
Thanks in advance. |
|
Back to top |
|
 |
smdavies99 |
Posted: Wed Dec 28, 2016 11:00 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
In your code
Code: |
SET OutputRoot.XMLNSC.gesmes:Envelope.Cube.Cube.
|
You have to specify the exact namespace for each element
Code: |
SET OutputRoot.XMLNSC.gesmes:Envelope.MyNameSpace1:Cube.MyNameSpace2Cube.
|
or similar. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
bharadwaj |
Posted: Thu Dec 29, 2016 1:36 pm Post subject: Modified my esql and it worked. |
|
|
Newbie
Joined: 28 Dec 2016 Posts: 2
|
Modified my Esql as below and it worked
DECLARE ns NAMESPACE 'namespace1';
DECLARE ns1 NAMESPACE 'namespace2';
SET OutputRoot.XMLNSC.ns:Envelope.(XMLNSC.NamespaceDecl)xmlns:gesmes = ns;
DECLARE refOutEnvelope REFERENCE TO OutputRoot.XMLNSC.ns:Envelope;
SET refOutEnvelope.(XMLNSC.NamespaceDecl)xmlns = ns1;
-- Should specify some namespace below,otherwise will get "Element must have a namespace specified if there is a default namespace in scope"
SET refOutEnvelope.ns1:Cube.ns1:Cube.(XMLNSC.Attribute)time = InputRoot.XMLNSC.ExchangeRatesSeries.Rates.Rate.EffectiveDate;
I am getting output as
<gesmes:Envelope xmlns:gesmes="namespace1" xmlns="namespace2">
<Cube>
<Cube time="2016-12-23"/>
</Cube>
</gesmes:Envelope>
Now i am modifying my esql to get output as below
<Cube>
<Cube time="2016-05-18">
<Cube currency="EUR" rate="4.4260" />
</Cube>
</Cube>
So I need the time attribute should be coming in one cube element and currency and rate should be coming in other cube element.
I am writing the below esql to achieve that
SET refOutEnvelope.ns1:Cube.ns1:Cube.(XMLNSC.Attribute)time = InputRoot.XMLNSC.ExchangeRatesSeries.Rates.Rate.EffectiveDate;
SET refOutEnvelope.ns1:Cube.ns1:Cube.(XMLNSC.Attribute)currency = InputRoot.XMLNSC.ExchangeRatesSeries.Code;
But I am getting output as
<Cube>
<Cube time="2016-12-23" currency="EUR"/>
</Cube>
Any suggestions are welcome.. |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu Dec 29, 2016 11:07 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Please learn to use the [C O D E] tags to make your posts easier to read. They are located right above the edit box. See my previous post and you can see what it does. Isn't that easier to read and understand? _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu Dec 29, 2016 11:11 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Have you looked at any of the samples provided with the product?
some of them you know, use namespaces. They are an invaluable tool to help you get going.
The answer to your problem is probably elsewhere in this forum.
There is a search tool available on the upper right of the page. Have you searched for things like namespaces to see if there is a solution you can use?
We like people to try to help themselves. That way you learn a lot quicker. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
timber |
Posted: Fri Dec 30, 2016 3:01 pm Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
smdavies99 said:
Quote: |
Please learn to use the [C O D E] tags |
Seconded. If we cannot read your question easily then we may not bother to answer it.
To create the second <Cube> tag, use a CREATE statement to create your output field and specify NEXTSIBLING as the position. Or use an index on the SET statement (but that is less efficient and not a good coding habit). |
|
Back to top |
|
 |
|