Author |
Message
|
schroederms |
Posted: Fri May 07, 2004 4:51 am Post subject: ESQL question |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
I'm wanting to grab the deepest vale of the tag <EXAMPLE_XML> within my XML, without any success. This tag may occur many times , this is where my problem.
Can anyone help ?
Thanks.
THIS IS WHAT THE INPUT LOOKS LIKE:
<APPLICATION_SERVICES>
<ACTION>INSERT/MODIFY</ACTION>
<APP_ID>application name here</APP_ID>
<FUNCTION>DEFAULT</FUNCTION>
<INSTANCE>DEF</INSTANCE>
<CLIENT>999</CLIENT>
<REALTIME>Y</REALTIME>
<SERVICEQ>application queue</SERVICEQ>
<SERVICEQMGR>application queue mgr</SERVICEQMGR>
<DESCRIPTION>this is a test</DESCRIPTION>
<EXAMPLEXML>
<EXAMPLE_XML>
<EXAMPLE_XML>
<EXAMPLE_XML>
<EXAMPLE_XML>
<EXAMPLE_XML>
<REQUEST>
<BOGUS></BOGUS>
</REQUEST>
</EXAMPLE_XML>
</EXAMPLE_XML>
</EXAMPLE_XML>
</EXAMPLE_XML>
</EXAMPLE_XML>
</EXAMPLEXML>
</APPLICATION_SERVICES>
THIS IS WHAT I WANT THE OUTPUT TO LOOK LIKE:
<APPLICATION_SERVICES>
<ACTION>INSERT/MODIFY</ACTION>
<APP_ID>application name here</APP_ID>
<FUNCTION>DEFAULT</FUNCTION>
<INSTANCE>DEF</INSTANCE>
<CLIENT>999</CLIENT>
<REALTIME>Y</REALTIME>
<SERVICEQ>application queue</SERVICEQ>
<SERVICEQMGR>application queue mgr</SERVICEQMGR>
<DESCRIPTION>this is a test</DESCRIPTION>
<EXAMPLEXML>
<EXAMPLE_XML>
<REQUEST>
<BOGUS></BOGUS>
</REQUEST>
</EXAMPLE_XML>
</EXAMPLEXML>
</APPLICATION_SERVICES> |
|
Back to top |
|
 |
Missam |
Posted: Fri May 07, 2004 5:48 am Post subject: |
|
|
Chevalier
Joined: 16 Oct 2003 Posts: 424
|
Try This
Code: |
DECLARE inptr REFERENCE TO InputBody."APPLICATION_SERVICES";
SET OutputRoot.XML."APPLICATION_SERVICES".ACTION = inptr.ACTION;
SET OutputRoot.XML."APPLICATION_SERVICES"."APP_ID" = inptr."APP_ID";
SET OutputRoot.XML."APPLICATION_SERVICES".FUNCTION = inptr.FUNCTION;
SET OutputRoot.XML."APPLICATION_SERVICES".INSTANCE = inptr.INSTANCE;
SET OutputRoot.XML."APPLICATION_SERVICES".CLIENT = inptr.CLIENT;
SET OutputRoot.XML."APPLICATION_SERVICES".REALTIME = inptr.REALTIME;
SET OutputRoot.XML."APPLICATION_SERVICES".SERVICEQ = inptr.SERVICEQ;
SET OutputRoot.XML."APPLICATION_SERVICES".SERVICEQMGR = inptr.SERVICEQMGR;
MOVE inptr TO inptr."EXAMPLEXML"."EXAMPLE_XML";
WHILE LASTMOVE(inptr) = TRUE DO
MOVE inptr TO inptr."EXAMPLE_XML";
END WHILE;
SET OutputRoot.XML."APPLICATION_SERVICES".EXAMPLEXML."EXAMPLE_XML".REQUEST.BOGUS = inptr.REQUEST.BOGUS; |
|
|
Back to top |
|
 |
fschofer |
Posted: Fri May 07, 2004 5:48 am Post subject: |
|
|
 Knight
Joined: 02 Jul 2001 Posts: 524 Location: Mainz, Germany
|
Hi, is the name of EXAMPLE_XML known and always the same ?
However, my solution may work without knowing the tag names.
Its untested, so it may have some syntax errors.
Please try out the two following to versions,
they should do the same but the second may be incorrect.
Code: |
DECLARE myref REFERENCE TO InputRoot.XML.APPLICATION_SERVICES.EXAMPLEXML;
WHILE ( LASTMOVE(myref) = TRUE ) AND ( FIELDNAME(myref.*[1].*[1]) <> 'REQUEST' ) ) DO
MOVE myref FIRSTCHILD;
END WHILE;
SET OutputRoot.XML.APPLICATION_SERVICES.EXAMPLEXML.*[1] = myref.*[1]; |
Code: |
DECLARE myref REFERENCE TO InputRoot.XML.APPLICATION_SERVICES.EXAMPLEXML;
WHILE ( LASTMOVE(myref) = TRUE ) AND ( FIELDNAME(myref.*[1]) <> 'REQUEST' ) ) DO
MOVE myref FIRSTCHILD;
END WHILE;
SET OutputRoot.XML.APPLICATION_SERVICES.EXAMPLEXML.*[1] = myref; |
|
|
Back to top |
|
 |
jefflowrey |
Posted: Fri May 07, 2004 5:55 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Both fschofer's example (at least one of them) and Missam's example should work.
But they both have certain assumptions behind them. Missam's example assumes that your nested tags are always called EXAMPLE_XML. Fschofer's example assumes that you want to walk down the "left most" side of the tree - always descend the first child.
If your requirements do not fit either of those two assumptions, you will need to change these examples to fit.
But what you're trying to do is a basic tree-walking procedure - so you should be able to find an algorithm that does what you want in some language or another and convert that to ESQL. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Missam |
Posted: Fri May 07, 2004 6:09 am Post subject: |
|
|
Chevalier
Joined: 16 Oct 2003 Posts: 424
|
Yes Jeff is right.Coding Always Changes with requirements.
Mr schroederms provided the input and told that how he wants to look the output and also based on his statement
Quote: |
I'm wanting to grab the deepest vale of the tag <EXAMPLE_XML> within my XML |
I assumed that a simple walk to the deepest element and a copy from there would solve his problem. |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri May 07, 2004 6:16 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Missam wrote: |
Yes Jeff is right.Coding Always Changes with requirements.
Mr schroederms provided the input and told that how he wants to look the output and also based on his statement
I assumed that a simple walk to the deepest element and a copy from there would solve his problem. |
Right, and there's nothing wrong with that.
I just wanted to make sure that schroederms understood the assumptions behind your code so that he adjust as needed.
And remind everyone that ESQL is just another programming language, and the logical message model is just another tree structure...  _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|