Author |
Message
|
MiLi |
Posted: Thu Jan 26, 2006 2:00 am Post subject: How to add a namespace to an incoming xml? |
|
|
Acolyte
Joined: 07 Oct 2005 Posts: 51
|
Hi, is it possible to just add a namespace to an incoming xml?
I have been looking for this and found nothing!
I'm thinking that it could be done by somehow adding a xmlns element to the xml and then use "reset content desciptor" to xmlns domain.
Is this possible or does anyone have any other ideas?
/Thanks |
|
Back to top |
|
 |
hemendra123 |
Posted: Thu Jan 26, 2006 7:48 am Post subject: |
|
|
Novice
Joined: 30 May 2005 Posts: 20
|
MiLi-
Just tweak the following snippet to meet your needs-
DECLARE refData REFERENCE TO INPUTROOT.XML;
-- Creata a XML field with name space.
CREATE LASTCHILD OF OutputRoot.XMLNS NAMESPACE(your_namepace) NAME(FIELDNAME(refData.(XML.Element)*[1]));
-- Attach the XML document
SET OutputRoot.XMLNS.your_namepace:{FIELDNAME(refData.(XML.Element)*[1])} = refData.(XML.Element)*[1];
-- Just to ensure for name space
SET OutputRoot.XMLNS.your_namepace:{FIELDNAME(refData.(XML.Element)*[1])}.(XML.NamespaceDecl)xmlns.your_namepace = your_namepace;
Hope this helps. _________________ Hemendr |
|
Back to top |
|
 |
MiLi |
Posted: Mon Jan 30, 2006 1:47 am Post subject: Not working |
|
|
Acolyte
Joined: 07 Oct 2005 Posts: 51
|
Hi
Thank for the reply
However, its not working. I'm using this code:
Code: |
DECLARE namespace NAMESPACE 'http://mynamespace';
DECLARE refData REFERENCE TO InputBody;
-- Creata a XML field with name space.
CREATE LASTCHILD OF OutputRoot.XMLNS NAMESPACE(namespace) NAME(FIELDNAME(refData.(XML.Element)*[1]));
-- Attach the XML document
SET OutputRoot.XMLNS.namespace:{FIELDNAME(refData.(XML.Element)*[1])} = refData.(XML.Element)*[1];
-- Just to ensure for name space
SET OutputRoot.XMLNS.namespace:{FIELDNAME(refData.(XML.Element)*[1])}.(XML.NamespaceDecl)xmlns.namespace = namespace;
|
I get a Value not valid, xml parser exception.
any input? _________________ IBM Certified System Administrator - WebSphere MQ V6.0
IBM Instructor - WebSphere MQ, WebSphere Message Broker |
|
Back to top |
|
 |
elvis_gn |
Posted: Mon Jan 30, 2006 1:58 am Post subject: |
|
|
 Padawan
Joined: 08 Oct 2004 Posts: 1905 Location: Dubai
|
Hi MiLi,
Why dont you use the debugger and tell us which line of code it is failing for.
Tell us the value you are sending as input..
Where are you getting the parser exception, at output, when the message leaves the flow ?
Regards. |
|
Back to top |
|
 |
MiLi |
Posted: Mon Jan 30, 2006 2:19 am Post subject: Ok |
|
|
Acolyte
Joined: 07 Oct 2005 Posts: 51
|
The error occurs on output, when teh message leaves the flow.
I changed the line
Code: |
(XML.NamespaceDecl)xmlns.namespace = namespace;
|
to
Code: |
(XML.NamespaceDecl)xmlns:namespace = namespace;
|
The flow is running fine but the message looks like this on output:
<namespace:ROOT xmlns:namespace="http://mynamespace">
<ZRSC050_1>
<ISIN_KOD>SE0102030405</ISIN_KOD>
<KUND_NR>6666666666</KUND_NR>
<TRANSAKTION_TYP>K</TRANSAKTION_TYP>
<NYINTRO_PAGAR_FL>J</NYINTRO_PAGAR_FL>
<fill_0></fill_0>
</ZRSC050_1>
<ZRSC050_2>
<NOM_BELOPP>5555555.555</NOM_BELOPP>
<AFFAR_KURS>3.000000</AFFAR_KURS>
<LIKVID_DATUM>20051220</LIKVID_DATUM>
<MOTPART></MOTPART>
<fill_1></fill_1>
</ZRSC050_2>
</namespace:ROOT>
This does not look like a valid xml to me!
So I tried to change the code line to add a default xmlns declaration:
Code: |
(XML.NamespaceDecl)xmlns = namespace;
|
But, Error on output is:
Text: Element must have a namespace specified if there is a default namespace in scope
Insert:Text: ZRSC050_1 _________________ IBM Certified System Administrator - WebSphere MQ V6.0
IBM Instructor - WebSphere MQ, WebSphere Message Broker |
|
Back to top |
|
 |
elvis_gn |
Posted: Mon Jan 30, 2006 2:45 am Post subject: |
|
|
 Padawan
Joined: 08 Oct 2004 Posts: 1905 Location: Dubai
|
Hi MiLi,
We got ur input, Can you tell us what exactly you want in the output. Also paste the snippet of code that you think is doing that.
Are you using a message set in the output ?
Regards. |
|
Back to top |
|
 |
MiLi |
Posted: Mon Jan 30, 2006 4:06 am Post subject: allright |
|
|
Acolyte
Joined: 07 Oct 2005 Posts: 51
|
I want to be able to add a namespace to any incoming xml on the xml domain.
My receiving system must have a namespace defined in order to start the right process!
So if I receive an xml
<ROOT>
<ZRSC050_1>
<ISIN_KOD>SE0102030405</ISIN_KOD>
<KUND_NR>6666666666</KUND_NR>
<TRANSAKTION_TYP>K</TRANSAKTION_TYP>
<NYINTRO_PAGAR_FL>J</NYINTRO_PAGAR_FL>
<fill_0></fill_0>
</ZRSC050_1>
<ZRSC050_2>
<NOM_BELOPP>5555555.555</NOM_BELOPP>
<AFFAR_KURS>3.000000</AFFAR_KURS>
<LIKVID_DATUM>20051220</LIKVID_DATUM>
<MOTPART></MOTPART>
<fill_1></fill_1>
</ZRSC050_2>
<ROOT>
I want to add xmlns "http://mynamespace" so it could go out on the xmlns domain as:
<ROOT xmlns="http://mynamespace">
<ZRSC050_1>
<ISIN_KOD>SE0102030405</ISIN_KOD>
<KUND_NR>6666666666</KUND_NR>
<TRANSAKTION_TYP>K</TRANSAKTION_TYP>
<NYINTRO_PAGAR_FL>J</NYINTRO_PAGAR_FL>
<fill_0></fill_0>
</ZRSC050_1>
<ZRSC050_2>
<NOM_BELOPP>5555555.555</NOM_BELOPP>
<AFFAR_KURS>3.000000</AFFAR_KURS>
<LIKVID_DATUM>20051220</LIKVID_DATUM>
<MOTPART></MOTPART>
<fill_1></fill_1>
</ZRSC050_2>
</ROOT>
As I described in the above posts I laborated with the code
hemendra123 posted without any success.
Is far as I can se, the code will only change the the root element.
Is there any other way, for example adding an attribute to root with the name xmlns and the use resetContentDescriptor to xmlns domain? _________________ IBM Certified System Administrator - WebSphere MQ V6.0
IBM Instructor - WebSphere MQ, WebSphere Message Broker |
|
Back to top |
|
 |
elvis_gn |
Posted: Mon Jan 30, 2006 4:12 am Post subject: |
|
|
 Padawan
Joined: 08 Oct 2004 Posts: 1905 Location: Dubai
|
Hi Mili,
If you are receiving ROOT as a tag and want to add "http://mynamespace" as u have shown, u have to add it as an attribute...
The way you have shown the required output, xmlns is not a namespace but an attribute, you will find sample code for adding an attribute on this site.
If you wanted "xmlns:ROOT...." then you should have used namespace..
Thus what hemendra123 said was right only your requirement is something else.
Regards. |
|
Back to top |
|
 |
|