Author |
Message
|
EnOne |
Posted: Tue Aug 24, 2004 1:18 pm Post subject: Combine two XML Parents |
|
|
 Centurion
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
|
I am stumped while trying to combine two XML Parents. For Example
<OT>
<ParentA>
<Child1>A</Child1>
<Child2>B</Child2>
<Child3>C</Child3>
</ParentA>
<ParentB>
<Child4>D</Child4>
<Child5>E</Child5>
<Child6>F</Child6>
</ParentB>
</OT>
My intended output is
<OT>
<Parent>
<Child1>A</Child1>
<Child2>B</Child2>
<Child3>C</Child3>
<Child4>D</Child4>
<Child5>E</Child5>
<Child6>F</Child6>
</Parent>
</OT>
I seem to be unable to put together an ESQL statement that will combine both ParentA and ParentB into one Parent |
|
Back to top |
|
 |
kirani |
Posted: Tue Aug 24, 2004 1:33 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Can you pose your ESQL code here? We can then see what's going wrong in your code. _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
EnOne |
Posted: Tue Aug 24, 2004 2:22 pm Post subject: |
|
|
 Centurion
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
|
I tried this
SET OutputRoot.XML.OT.Parent = InputRoot.XML.OT.ParentA;
SET OutputRoot.XML.OT.Parent = InputRoot.XML.OT.ParentB;
and the output had the ParentB values overwriting the ParentA values
<OT>
<Parent>
<Child4>D</Child4>
<Child5>E</Child5>
<Child6>F</Child6>
</Parent>
<OT>
I also attempted different SELECT statements to no avail
SET OutputRoot.XML.OT[] = (SELECT R.ParentA AS Parent, R.ParentB AS Parent FROM InputRoot.OT[] AS R); |
|
Back to top |
|
 |
martinrydman |
Posted: Wed Aug 25, 2004 8:50 am Post subject: |
|
|
 Centurion
Joined: 30 Jan 2004 Posts: 139 Location: Gothenburg, Sweden
|
Hi,
Sorry, but there's no 'smart' way round this one. You'll have to assig each output field specifically:
Code: |
SET OutputRoot.XML.OT.Parent.Child1 = InputRoot.XML.OT.ParentA.Child1;
SET OutputRoot.XML.OT.Parent.Child2 = InputRoot.XML.OT.ParentA.Child2;
SET OutputRoot.XML.OT.Parent.Child3 = InputRoot.XML.OT.ParentA.Child3;
SET OutputRoot.XML.OT.Parent.Child4 = InputRoot.XML.OT.ParentB.Child4;
...
|
If you had more fields, like 10 or 20 per Parent, there are some clever things you could do with loops, FIELDNAME and the {} construct, but come back if that's of any interest.
/Martin |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Aug 25, 2004 10:02 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I haven't tried this myself, but you should be able to use the LIST constructor to create a LIST of the children of each Parent.
Something like
Code: |
Set OutputRoot.XML.OT.Parent = LIST(InputRoot.XML.OT.ParentA.[]*, InputRoot.XML.OT.ParentB.*[]); |
Or maybe the ROW constructor...  _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
EnOne |
Posted: Wed Aug 25, 2004 10:52 am Post subject: |
|
|
 Centurion
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
|
I thought that the LIST and ROW were used to generate new values not reformat input values.
This OT/ParentA/Child and OT/ParentB/Child is an example of the actual input. The origional message has 100+ elements each with a unique name below the parent elements. I put in the example to keep the size of the message managable.
What were the Ideas regarding loops, FIELDNAME and the {} construct |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Aug 25, 2004 11:08 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
njpeeke wrote: |
I thought that the LIST and ROW were used to generate new values not reformat input values. |
Why?
I've certainly done things with the ROW constructor like
Code: |
Set OutputRoot.MRM.Root.ChildTree = ROW(InputRoot.XML.Root.FieldA as ChildNode1, InputRoot.XML.Root.FieldB as ChildNode2); |
You might need to play around with the syntax a bit, but one of these should work. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
EnOne |
Posted: Wed Aug 25, 2004 2:18 pm Post subject: |
|
|
 Centurion
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
|
but that does not solve my problem of having to type out all the element names in order to get the children of both parents. I'm trying to join two large columns of elements into one column of elements. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Aug 25, 2004 3:06 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Again, if you try using the ".*[]" syntax to indicate "all children", I am hoping that this will work.
What happens when you try the code I posted?
Code: |
Set OutputRoot.XML.OT.Parent = LIST(InputRoot.XML.OT.ParentA.[]*, InputRoot.XML.OT.ParentB.*[]); |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
EnOne |
Posted: Thu Aug 26, 2004 6:17 am Post subject: |
|
|
 Centurion
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
|
This error is returned
BIP2472E: (10, 37) : Invalid LIST member.
A LIST cannot contain another LIST as one of its members.
Correct the syntax of the expression and redeploy the message flow.
when I use this code
Set OutputRoot.XML.OT.Parent = LIST{InputRoot.XML.OT.ParentA.*[], InputRoot.XML.OT.ParentB.*[]};
or
Set OutputRoot.XML.OT.Parent = LIST{InputRoot.XML.OT.ParentA.*[]};
It looks like LIST does not allow []
----------
Set OutputRoot.XML.OT.Parent.*[] = LIST{InputRoot.XML.OT.ParentA.*,InputRoot.XML.OT.ParentB.*};
returns
<XMLFull>
<OT>
<Parent>
<Child1>A</Child1>
<Child4>D</Child4>
</Parent>
</OT>
</XMLFull>
but i am unable to get it to go through all the child elements  |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Aug 26, 2004 6:19 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Try the ROW operator, instead.
Or try using .* in your original Select, to select the children.
Something like
Code: |
Set OutputRoot.XML.OT.Parent.*[] = (Select R.*, T.* from InputRoot.XML.OT.ParentA as R, InputRoot.XML.OT.ParentB as T) |
The basic point is that you want to get all of the children of each node. You don't want to copy the node itself, just all it's children. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
mgk |
Posted: Fri Aug 27, 2004 5:26 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi,
The following code performs the transform required in your original post. You should be able to tweek it to fit your actual requirements.
Regards,
Code: |
/*local variables*/
DECLARE inRef REFERENCE TO InputRoot.XML.OT.ParentA;
DECLARE tmpRef REFERENCE TO inRef;
/*create output destination*/
CREATE LASTCHILD OF OutputRoot.XML.OT DOMAIN 'XML' NAME 'Parent';
/*loop over outer Parent elements, moving inRef to each in turn*/
WHILE LASTMOVE(inRef) DO
MOVE tmpRef TO inRef;
MOVE tmpRef FIRSTCHILD;
/*loop over inner child elements, moving tmpRef to each in turn*/
WHILE LASTMOVE(tmpRef) DO
/*copy each child element to destination*/
CREATE LASTCHILD OF OutputRoot.XML.OT.Parent FROM tmpRef;
MOVE tmpRef NEXTSIBLING REPEAT TYPE;
END WHILE;
MOVE inRef NEXTSIBLING REPEAT TYPE;
END WHILE; |
_________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
javaforvivek |
Posted: Sun Aug 29, 2004 11:26 pm Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Hi mgk,
I tried your code for following message:
<TopMessage>
<Line>
<bank_id>BG12345</bank_id>
<account_id>SB0011</account_id>
<cheque_no>445566</cheque_no>
</Line>
<Line>
<bank_id>BG12345</bank_id>
<account_id>SB0012</account_id>
<cheque_no>90900</cheque_no>
</Line>
</TopMessage>
It works fine, but then it just adds another <Parent> to <TopMessage> and does not delete <Line> elements.
My output message looks like this:
<TopMessage>
<Line>
<bank_id>BG12345</bank_id>
<account_id>SB0011</account_id>
<cheque_no>445566</cheque_no>
</Line>
<Line>
<bank_id>BG12345</bank_id>
<account_id>SB0012</account_id>
<cheque_no>90900</cheque_no>
</Line>
<Parent>
<bank_id>BG12345</bank_id>
<account_id>SB0011</account_id>
<cheque_no>445566</cheque_no>
<bank_id>BG12345</bank_id>
<account_id>SB0012</account_id>
<cheque_no>90900</cheque_no>
</Parent>
</TopMessage>
My message is similar to njpeeke, and at least I don't require <Line> elements to prevail.. ( I guess, even njpeeke doesn't require his <ParentA> and <ParentB> to prevail). So do I require to have another loop to delete the <Line> elements or is there just a line of ESQL code, that I should add to your code, to do this? If yes, what is that line? _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
mgk |
Posted: Mon Aug 30, 2004 3:17 pm Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi,
You should not get the <Line> tags with the code I posted. I guess you have either changed it in some way that breaks it, or copied InputRoot to OutputRoot before performing the transform (as the transform will not remove existing children (of <TopMessage> in your case), just add children. Could you post the exact code you used please, and the version of the product you are using.
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
EnOne |
Posted: Tue Aug 31, 2004 3:22 pm Post subject: |
|
|
 Centurion
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
|
thanks mgk, I was able to adapt your code and it worked almost perfectly. I think that javaforvivek had 'Copy Entire Message' radio button checked. What he recieved was as what I did when I was keeping my entire message.
The only change I had to make to your code was to change
MOVE tmpRef NEXTSIBLING REPEAT TYPE;
END WHILE;
MOVE inRef NEXTSIBLING REPEAT TYPE;
to
MOVE tmpRef NEXTSIBLING;
END WHILE;
MOVE inRef NEXTSIBLING;
i could find no difference in my output, but I recieved a syntax error that didn't affect anything if i ignored it when i tried with the REPEAT TYPE still there. Maybe it's a difference between 2.1 and 5 |
|
Back to top |
|
 |
|