|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Detach an XML tag |
« View previous topic :: View next topic » |
Author |
Message
|
Rockon |
Posted: Fri Aug 05, 2005 10:48 am Post subject: Detach an XML tag |
|
|
Apprentice
Joined: 24 May 2004 Posts: 43
|
Hi All,
I have an input message wherein I have to look for an attribute in each of the lines and send out the message with lines containing only that attribute(tsi_prod_id).
Input Message:
Code: |
<SLRequest Name="handleGPData" >
<SLParam Value="XML">
<GPData ColumnSpecification="PARTIAL" >
<tsi_man DELTA_STATUS="D_INSERT" ctry_code="CA">
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="1" tsi_prod_id="VM3019" />
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="2" itm_description="E/A,LX BPLR STD RH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="3" itm_description="E/A,LX BPLR STD RH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="4" itm_description="E/A,LX BPLR STD RH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="5" itm_description="E/A,LX BPLR STD LH " tsi_prod_id="VM3020" site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="6" itm_description="E/A,LX BPLR STD LH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="7" itm_description="E/A,LX BPLR STD LH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="8" itm_description="E/A,LX BPLR STD LH " site_id="1"/>
</tsi_man>
</GPData>
</SLParam>
<SLParam Value=""/>
</SLRequest>
|
Expected output Message:
Code: |
<SLRequest Name="handleGPData">
<SLParam Value="XML">
<GPData ColumnSpecification="PARTIAL">
<tsi_man DELTA_STATUS="D_INSERT" ctry_code="CA">
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="1" tsi_prod_id="VM3019"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="5" itm_description="E/A,LX BPLR STD LH " tsi_prod_id="VM3020" site_id="1"/>
</tsi_man>
</GPData>
</SLParam>
<SLParam Value=""/>
</SLRequest>
|
I wrote the ESQL to get this desired effect which looks like:
Code: |
CALL CopyEntireMessage();
DECLARE Total_Count INT;
SET Total_Count=CARDINALITY(OutputRoot.XML."SLRequest"."SLParam"."GPData"."tsi_man"."tsi_man_itm"[]);
DECLARE Count INT 1;
DECLARE outputref REFERENCE TO OutputRoot.XML."SLRequest"."SLParam"."GPData"."tsi_man"."tsi_man_itm"[1];
--WHILE(LASTMOVE(outputref)) DO
WHILE (Count <= Total_Count) DO
MOVE outputref TO OutputRoot.XML."SLRequest"."SLParam"."GPData"."tsi_man"."tsi_man_itm"[Count];
IF(OutputRoot.XML."SLRequest"."SLParam"."GPData"."tsi_man"."tsi_man_itm"[Count].(XML.attr)tsi_prod_id is NULL) THEN
SET Environment.Variable.tsi_prod_id=Count;
DETACH outputref;
SET outputref=NULL;
--SET OutputRoot.XML."SLRequest"."SLParam"."GPData"."tsi_man"."tsi_man_itm"[Count] = NULL;
END IF;
SET Count= Count+1;
--MOVE outputref NEXTSIBLING REPEAT TYPE NAME;
END WHILE;
|
But the output is not of the desired effect.I get is as:
Code: |
<SLRequest Name="handleGPData">
<SLParam Value="XML">
<GPData ColumnSpecification="PARTIAL">
<tsi_man DELTA_STATUS="D_INSERT" ctry_code="CA">
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="1" tsi_prod_id="VM3019"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="3" itm_description="E/A,LX BPLR STD RH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="5" itm_description="E/A,LX BPLR STD LH " tsi_prod_id="VM3020" site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="7" itm_description="E/A,LX BPLR STD LH " site_id="1"/>
</tsi_man>
</GPData>
</SLParam>
<SLParam Value=""/>
</SLRequest>
|
I tried looking at the trace file but even though it says that the tag is being deleted, i dont see it in the output message.
I'll appreciate if someone can point to me the mistake m doing in this code.
Thankyou |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Aug 05, 2005 10:51 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Usually, it is better to call CopyHeaders, and then only copy the stuff you WANT, rather than trying to copy everything and then remove the stuff you don't want.
And more efficient, too. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Rockon |
Posted: Fri Aug 05, 2005 11:16 am Post subject: |
|
|
Apprentice
Joined: 24 May 2004 Posts: 43
|
Hi jefflowrey,
I know what you mean...but my problem is there are other numeours attributes at the root level and at the sub level and I couldnt figure out to get them all using copymessageheaders.Hence this approach.The thing I dont understand is the code logically seems correct,but the output isnt as desired.
May be I am missing something somewhere.....please let me know if you have done something in similar lines before....Thankyou |
|
Back to top |
|
 |
javaforvivek |
Posted: Sat Aug 06, 2005 3:51 am Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
A couple of assumptions that I had made in this reply are:
1. tsi_man element is the first element under GPData element.
2. Occuerence of tsi_man element in GPData element is either zero or one.
In your code, you soley work on OutputRoot. From your given Input message and ESQL code, it is evident that you first copy entire input message to output message. So first line of your executable code is:
Code: |
OutputRoot = InputRoot
|
When you execute it in the while loop, for first occurrence of tsi_man_itm element, ie, for OutputRoot.XML."SLRequest"."SLParam"."GPData"."tsi_man"."tsi_man_itm"[1],
it checks for tsi_prod_id is/isn't NULL, it finds that it is NOT NULL, and moves the outputref to OutputRoot.XML."SLRequest"."SLParam"."GPData"."tsi_man"."tsi_man_itm"[2],
Your OutputRoot looks like this:
Code: |
<SLRequest Name="handleGPData" >
<SLParam Value="XML">
<GPData ColumnSpecification="PARTIAL" >
<tsi_man DELTA_STATUS="D_INSERT" ctry_code="CA">
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="1" tsi_prod_id="VM3019" />
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="2" itm_description="E/A,LX BPLR STD RH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="3" itm_description="E/A,LX BPLR STD RH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="4" itm_description="E/A,LX BPLR STD RH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="5" itm_description="E/A,LX BPLR STD LH " tsi_prod_id="VM3020" site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="6" itm_description="E/A,LX BPLR STD LH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="7" itm_description="E/A,LX BPLR STD LH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="8" itm_description="E/A,LX BPLR STD LH " site_id="1"/>
</tsi_man>
</GPData>
</SLParam>
<SLParam Value=""/>
</SLRequest>
|
again it checks for tsi_prod_id is/isn't NULL, it finds that it is NULL, and goes in the IF..THEN..ENDIF clause. Here it detaches outputref and sets it to null.
In this process your OutputRoot is altered. Now it looks like this:
Code: |
<SLRequest Name="handleGPData" >
<SLParam Value="XML">
<GPData ColumnSpecification="PARTIAL" >
<tsi_man DELTA_STATUS="D_INSERT" ctry_code="CA">
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="1" tsi_prod_id="VM3019" />
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="3" itm_description="E/A,LX BPLR STD RH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="4" itm_description="E/A,LX BPLR STD RH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="5" itm_description="E/A,LX BPLR STD LH " tsi_prod_id="VM3020" site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="6" itm_description="E/A,LX BPLR STD LH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="7" itm_description="E/A,LX BPLR STD LH " site_id="1"/>
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="8" itm_description="E/A,LX BPLR STD LH " site_id="1"/>
</tsi_man>
</GPData>
</SLParam>
<SLParam Value=""/>
</SLRequest>
|
So in the third iteration, your outputref will point to :
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="4" itm_description="E/A,LX BPLR STD RH " site_id="1"/>
instead of
<tsi_man_itm DELTA_STATUS="D_INSERT" ctry_code="CA" man_itm_id="3" itm_description="E/A,LX BPLR STD RH " site_id="1"/>
So is true for the rest of the iterations. Hence you are getting that output which you have shown here.
Either You find out some other way of achieving what you intend,
OR
Just loop through OutputRoot and delete those tsi_man_itm elements where tsi_prod_id IS NULL. _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
JT |
Posted: Mon Aug 08, 2005 6:01 am Post subject: |
|
|
Padawan
Joined: 27 Mar 2003 Posts: 1564 Location: Hartford, CT.
|
Why not do as Jeff suggested, and extract just the elements you need:
Code: |
SET OutputRoot.XML."SLRequest"."SLParam"."GPData"."tsi_man".tsi_man_itm[] =
SELECT T FROM InputRoot.XML."SLRequest"."SLParam"."GPData"."tsi_man".tsi_man_itm[] AS T
WHERE T.(XML.Attribute)tsi_prod_id IS NOT NULL); |
|
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|