Author |
Message
|
Carl Bloy |
Posted: Tue Aug 23, 2005 8:16 am Post subject: XML in ESQL, how? |
|
|
Acolyte
Joined: 16 Dec 2003 Posts: 69 Location: England
|
Hi all,
I was wondering if anyone can explain whether it's possible to represent the following XML in ESQL?
<RESY >
<ADDRESSNUMBER>11</ADDRESSNUMBER>
<ADDRESSINDICATOR>P</ADDRESSINDICATOR>
<NAMESCOUNT>2</NAMESCOUNT>
<NAMESEQUENCENUMBER>01</NAMESEQUENCENUMBER>
<DATEFROM_DD>23</DATEFROM_DD>
<DATEFROM_MM>08</DATEFROM_MM>
<DATEFROM_CCYY>2001</DATEFROM_CCYY>
<DATETO_DD>23</DATETO_DD>
<DATETO_MM>08</DATETO_MM>
<DATETO_CCYY>2003</DATETO_CCYY>
<NAMESEQUENCENUMBER>11</NAMESEQUENCENUMBER>
<DATEFROM_DD>23</DATEFROM_DD>
<DATEFROM_MM>08</DATEFROM_MM>
<DATEFROM_CCYY>2001</DATEFROM_CCYY>
<DATETO_DD>23</DATETO_DD>
<DATETO_MM>08</DATETO_MM>
<DATETO_CCYY>2003</DATETO_CCYY>
</RESY>
Many thanks
CArl. _________________ Regards
Carl |
|
Back to top |
|
 |
djeripo |
Posted: Tue Aug 23, 2005 8:24 am Post subject: |
|
|
 Master
Joined: 25 Jan 2004 Posts: 225
|
Simple XML one - one mapping.Assuming the XML you posted comes as Input to Compute node.
SET OutputRoot.XML.Resy.AddressNumber = InputRoot.XML.RESY.ADDRESSNUMBER;
----------
----------
Last edited by djeripo on Tue Aug 23, 2005 8:24 am; edited 1 time in total |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Aug 23, 2005 8:24 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Yes. This should be straight forward, bearing in mind that there are multiple instances of several fields. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Carl Bloy |
Posted: Wed Aug 24, 2005 2:07 am Post subject: It's not that simple... |
|
|
Acolyte
Joined: 16 Dec 2003 Posts: 69 Location: England
|
It's not as easy as doing one to one mapping, i'm not sure how to map the repeating elements?
If you map them as one to one then the second one ovwerwites the first one.
If you map them with an array index then the order of the elements changes? _________________ Regards
Carl |
|
Back to top |
|
 |
javaforvivek |
Posted: Wed Aug 24, 2005 2:56 am Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Carl Bloy wrote:
Quote: |
i'm not sure how to map the repeating elements?
|
It depends upon how many elements are repeating. From your message I see that elements from 'NAMESEQUENCENUMBER' to 'DATETO_CCYY' form a set of related elements. This set repeats itself n number of times.
Now, If you want to copy entire input message to output message then there is one simple statement
Code: |
OutputRoot = InputRoot |
But if you want to copy only selective (and repeating) elements from input to output then there are several different ways to do it:
Code: |
DECLARE NAMESEQUENCENUMBERCard INTEGER CARDINALITY (InputRoot.XML.RESY.NAMESEQUENCENUMBER[]);
DECLARE i INTEGER 1;
CREATE FIELD OutputRoot.XML.RESY;
CREATE FIRSTCHILD OF OutputRoot.XML.RESY NAME 'ADDRESSNUMBER' VALUE InputRoot.XML.RESY.ADDRESSNUMBER;
WHILE ( i <= NAMESEQUENCENUMBERCard) DO
CREATE LASTCHILD OF OutputRoot.XML.RESY NAME 'NAMESEQUENCENUMBER' VALUE InputRoot.XML.RESY.NAMESEQUENCENUMBER[i];
CREATE LASTCHILD OF OutputRoot.XML.RESY NAME 'DATEFROM_DD' VALUE InputRoot.XML.RESY.DATEFROM_DD[i];
CREATE LASTCHILD OF OutputRoot.XML.RESY NAME 'DATEFROM_MM' VALUE InputRoot.XML.RESY.DATEFROM_MM[i];
SET i = i +1;
END WHILE;
|
You can use REFERENCE to both input and output roots for looping purpose. And more efficient code can be written based on what I have coded here.
For further details of 'Handling Large XML Messages' please see:
http://publib.boulder.ibm.com/infocenter/wbihelp/index.jsp?topic=/com.ibm.etools.mft.doc/ac16740_.htm _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
Carl Bloy |
Posted: Wed Aug 24, 2005 6:57 am Post subject: Many thanks |
|
|
Acolyte
Joined: 16 Dec 2003 Posts: 69 Location: England
|
Vivek,
Many thanks for your response, exactly what we were looking for works a treat.
Much appreciated!!
Regards
Carl. _________________ Regards
Carl |
|
Back to top |
|
 |
Lillian |
Posted: Wed Oct 12, 2005 11:09 pm Post subject: |
|
|
Centurion
Joined: 15 Apr 2002 Posts: 102
|
Hi Vivek
i am trying to get a similar output but where the repeating type is the parent of two children. ie
<NAMESEQUENCENUMBER>
<DATEFROM_DD>23</DATEFROM_DD>
<DATEFROM_MM>08</DATEFROM_MM>
</NAMESEQUENCENUMBER>
<NAMESEQUENCENUMBER>
<DATEFROM_DD>23</DATEFROM_DD>
<DATEFROM_MM>08</DATEFROM_MM>
</NAMESEQUENCENUMBER>
<NAMESEQUENCENUMBER>
<DATEFROM_DD>23</DATEFROM_DD>
<DATEFROM_MM>08</DATEFROM_MM>
</NAMESEQUENCENUMBER>
I keep getting the reference point of creating the next sibling wrong. |
|
Back to top |
|
 |
javaforvivek |
Posted: Thu Oct 13, 2005 12:39 am Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Lillian,
First of all your XML is NOT valid XML, because it doesn't have the root tag. I have assumed that your output will be encapsulated in <Message> Root tag. Here is the code for the same output message that you have described:
Code: |
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
-- CALL CopyEntireMessage();
CREATE FIELD OutputRoot.XML.Message;
CREATE FIRSTCHILD OF OutputRoot.XML.Message DOMAIN ('XML') NAME 'NAMESEQUENCENUMBER';
CREATE FIRSTCHILD OF OutputRoot.XML.Message.NAMESEQUENCENUMBER[1] NAME 'DATEFROM_DD' VALUE '23';
CREATE LASTCHILD OF OutputRoot.XML.Message.NAMESEQUENCENUMBER[1] NAME 'DATEFROM_MM' VALUE '08';
CREATE NEXTSIBLING OF OutputRoot.XML.Message.NAMESEQUENCENUMBER[1] NAME 'NAMESEQUENCENUMBER';
CREATE FIRSTCHILD OF OutputRoot.XML.Message.NAMESEQUENCENUMBER[2] NAME 'DATEFROM_DD' VALUE '24';
CREATE LASTCHILD OF OutputRoot.XML.Message.NAMESEQUENCENUMBER[2] NAME 'DATEFROM_MM' VALUE '08';
CREATE NEXTSIBLING OF OutputRoot.XML.Message.NAMESEQUENCENUMBER[2] NAME 'NAMESEQUENCENUMBER';
CREATE FIRSTCHILD OF OutputRoot.XML.Message.NAMESEQUENCENUMBER[3] NAME 'DATEFROM_DD' VALUE '25';
CREATE LASTCHILD OF OutputRoot.XML.Message.NAMESEQUENCENUMBER[3] NAME 'DATEFROM_MM' VALUE '08';
RETURN TRUE;
END; |
which gives the output of
<Message>
<NAMESEQUENCENUMBER>
<DATEFROM_DD>23</DATEFROM_DD>
<DATEFROM_MM>08</DATEFROM_MM>
</NAMESEQUENCENUMBER>
<NAMESEQUENCENUMBER>
<DATEFROM_DD>24</DATEFROM_DD>
<DATEFROM_MM>08</DATEFROM_MM>
</NAMESEQUENCENUMBER>
<NAMESEQUENCENUMBER>
<DATEFROM_DD>25</DATEFROM_DD>
<DATEFROM_MM>08</DATEFROM_MM>
</NAMESEQUENCENUMBER>
</Message>
I have assumed that NAMESEQUENCENUMBER is repeated three times only. But if you are not sure of the repeat count, then you may have to use the WHILE loop ( or whatever looping you can think of) after creating first occurrence of NAMESEQUENCENUMBER. _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
Lillian |
Posted: Thu Oct 13, 2005 1:03 am Post subject: |
|
|
Centurion
Joined: 15 Apr 2002 Posts: 102
|
Thanks again... It works.
I added the snippet into a loop and it was supposed to be within a root element as assumed. |
|
Back to top |
|
 |
javaforvivek |
Posted: Thu Oct 13, 2005 4:30 am Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Please Please go through the link I had mentioned in my earlier posts. It is very useful in teaching how you can handle large XML Messages.
You need to understand:
What do the NEXTSIBLING and FIRST/LASTCHILD mean.
How the CREATE statements are more performance friendly than direct SET statements.
How to build an output message tree from input message tree.
I have found ESQL as the easiest part of WBIMB to learn and message modelling concepts (especially CWF and TDS Wire Formats) as the hardest part to learn...  _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
|