Author |
Message
|
javaforvivek |
Posted: Tue Aug 10, 2004 3:05 am Post subject: Adding new record to XML dusring processing in Message Flow |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Hi,
I have a following XML Message:
<File>
<Record>
<Amount>800</Amount>
<AmountTotal>4000</AmountTotal>
<AmountSubTotal>2000</AmountSubTotal>
</Record>
</File>
My business rules say that I should apply some business logic to this message and append a new <Record> tag in the above message.
So that the Output Message looks like this:
<File>
<Record>
<Amount>800</Amount>
<AmountTotal>4000</AmountTotal>
<AmountSubTotal>2000</AmountSubTotal>
</Record>
<Record>
<Amount>800</Amount>
<AmountTotal>2000</AmountTotal> <!-- the value of AmountTotal field is changed due to business conditions-->
<AmountSubTotal>2000</AmountSubTotal>
</Record>
</File>
So how to add this new Record tag to the existing XML Input message and produce an Output XML Message with additional Record Tag?
Can anybody give me the ESQL code?
I tried following two codes, but they failed..
Code1:
Code: |
DECLARE recCardinality INTEGER CARDINALITY(OutputRoot.XML.Docket.Record[]);
CREATE FIELD OutputRoot.XML.Docket.Record[recCardinality + 1];
--Add the internal elements like Amount and AmountSubTotal
|
Code2:
Code: |
DECLARE newRecord REFERENCE TO OutputRoot.XML.Docket.Record[recCardinality + 1];
--Add the internal elements like Amount and AmountSubTotal
|
_________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
wooda |
Posted: Tue Aug 10, 2004 4:42 am Post subject: |
|
|
 Master
Joined: 21 Nov 2003 Posts: 265 Location: UK
|
Hi,
what's wrong with ...
Code: |
DECLARE recCardinality INTEGER CARDINALITY(OutputRoot.XML.Docket.Record[]);
SET OutputRoot.XML.Docket.Record[recCardinality + 1].Amount = '800';
SET OutputRoot.XML.Docket.Record[recCardinality + 1].AmountTotal = '2000';
SET OutputRoot.XML.Docket.Record[recCardinality + 1].AmountSubTotal = '2000'; |
|
|
Back to top |
|
 |
javaforvivek |
Posted: Tue Aug 10, 2004 5:34 am Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Hi Alex,
It is working fine..
Can we also insert a tag inbetween already existing tag dusring processing the message in message flow?
For eg,
<File>
<Record>1</Record>
<Record>2</Record>
</File>
I want to insert an extra <Record> Tag inbetween <Record>1 and <Record>2, so that my output message looks like:
<File>
<Record>1</Record>
<Record>New Tag Inserted</Record><!--newly inserted tag-->
<Record>2</Record>
</File>
If yes, how to do it? _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
wooda |
Posted: Tue Aug 10, 2004 7:13 am Post subject: |
|
|
 Master
Joined: 21 Nov 2003 Posts: 265 Location: UK
|
Yes of course.
eg.
Code: |
SET OutputRoot.XML.File.Record[1] = InputRoot.XML.File.Record[1];
SET OutputRoot.XML.File.Record[2] = 'New Tag Inserted';
SET OutputRoot.XML.File.Record[3] = InputRoot.XML.File.Record[2]; |
Come on Vivek, you could have worked that out for yourself.  |
|
Back to top |
|
 |
javaforvivek |
Posted: Tue Aug 10, 2004 7:48 am Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Yeah Alex,
I knew that.. but it's a sort of adjusting the offset betwwen indices of the records... I thought, there might be some other way, where by we will avoid writing the last line of the code.
Code: |
SET OutputRoot.XML.File.Record[3] = InputRoot.XML.File.Record[2];
|
As in Java, we have Vector method insertElementAt(Oject object,int index)
where we can insert an element in Vector at a particular index and we don't have to adjust the indices (Cardinality in WBIMB terms!!) of the rest of the elements.
But now I guess, we have to adjust the offset between the indices as in line3 of the given code....
Sorry for the trouble Alex... but it's like, I like to check whether there are some new ways of doing things or not..!!!!!  _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Aug 10, 2004 7:51 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Rather than asking questions that are directly addressable in the documentation, you should look these things up yourself.
Like, if you had look at the function CREATE, you would see that it allows you to specify various POSITIONAL options (like NEXTSIBLING). _________________ I am *not* the model of the modern major general.
Last edited by jefflowrey on Tue Aug 10, 2004 8:05 am; edited 1 time in total |
|
Back to top |
|
 |
fazz |
Posted: Tue Aug 10, 2004 7:56 am Post subject: |
|
|
 Centurion
Joined: 20 Feb 2004 Posts: 144 Location: England
|
How about....
Code: |
CREATE NEXTSIBLING OF OutputRoot.XML.File.Record[2] NAME 'Record' |
|
|
Back to top |
|
 |
shanson |
Posted: Thu Aug 12, 2004 2:27 am Post subject: |
|
|
 Partisan
Joined: 17 Oct 2003 Posts: 344 Location: IBM Hursley
|
A comment on your XML. Using <Record> as the tag for both a position indicator and for a data record does not seem clever to me. Think about what the model would look like in XML Schema. You would be much better off adding an attribute to the <Record> element to give the position, eg, <Record pos='1'>......</Record>
<Record pos='2'>......</Record> |
|
Back to top |
|
 |
|