|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
question regarding REFERENCE, FIELDNAME and XML |
« View previous topic :: View next topic » |
Author |
Message
|
ernest-ter.kuile |
Posted: Tue Oct 15, 2002 6:55 am Post subject: question regarding REFERENCE, FIELDNAME and XML |
|
|
 Apprentice
Joined: 13 May 2002 Posts: 49 Location: KLM Holland
|
I have different XML messages that all have a common part that need
to be modified in a compute node.
example :
Code: |
<?xml ...>
<MESSAGE_TYPE_1_>
<common_part>
<timestamp>the_time</timestamp>
<flightnumber carrier="KL">1234</flightnumber>
</common_part>
<different_part_1>
...
</different_part_1>
</MESSAGE_TYPE_1_> |
same for MESSAGE_TYPE_2_, _3_, _4_, etc ...
how can I access
InputBody.MESSAGE_TYPE_1_.common_part.timestamp
InputBody.MESSAGE_TYPE_2_.common_part.timestamp
InputBody.MESSAGE_TYPE_3_.common_part.timestamp
InputBody.MESSAGE_TYPE_4_.common_part.timestamp
without needing to know if the message is of type MESSAGE_TYPE_1_, _2_,_ 3_, _4_.
I thought I might use REFERENCE and FIELDNAME to do this.
but if so, how ?
in the documentation, REFERENCE if often used in the context of "dynamic", however, how do I change the reference value without the system telling me that it was already declared ?
and of course, something like :
Code: |
DECLARE timestamp REFERENCE TO InputBody.FIELDNAME(InputBody.(XML.Element)[1]); |
does not work.
Ernest |
|
Back to top |
|
 |
lillo |
Posted: Tue Oct 15, 2002 8:17 am Post subject: |
|
|
Master
Joined: 11 Sep 2001 Posts: 224
|
Hi,
It is easy. The reference variable should be:
Code: |
DECLARE refVariable REFERENCE TO InputRoot.XML.*[LAST].common_part.timestamp;
|
Cheers, _________________ Lillo
IBM Certified Specialist - WebSphere MQ |
|
Back to top |
|
 |
ernest-ter.kuile |
Posted: Tue Oct 15, 2002 11:32 pm Post subject: |
|
|
 Apprentice
Joined: 13 May 2002 Posts: 49 Location: KLM Holland
|
Indeed easy, but not obvious.
thanks.
Ernest. |
|
Back to top |
|
 |
ernest-ter.kuile |
Posted: Thu Oct 17, 2002 7:26 am Post subject: |
|
|
 Apprentice
Joined: 13 May 2002 Posts: 49 Location: KLM Holland
|
lillo wrote: |
Hi,
It is easy. The reference variable should be:
Code: |
DECLARE refVariable REFERENCE TO InputRoot.XML.*[LAST].common_part.timestamp;
|
|
Well, after a second look it has a flaw: it doesn't work. At least not always.
The XML parser seems to keep the formating of the XML input interlaced in XML tree, so even though they have no influence on the XML itself, TABs and LFs are visible and can be read back in the tree.
Unfortunalty, the XML I'm sending in has a nice formating applied to it to allow for humans to read it too.
so
Code: |
<?xml ...>
<MESSAGE_TYPE_1_>
<common_part>
... snip snip snip ...
</MESSAGE_TYPE_1_> |
will in a trace node look like this
Code: |
(0x5000018)XML = (
(0x6000011) = '1.0'
(0x6000012) = 'UTF-8'
)
(0x6000002) = '<cr><lf>'
(0x1000000)MESSAGE_TYPE_1_ = (
(0x2000000) = '<cr><lf><tab>'
(0x1000000)common_part = (
(0x2000000) = '<cr><lf><tab>'
... snip snip snip ...
)
(0x6000002) = '<cr><lf>' |
note : I added the <cr><lf>, in the log file they are the actual characters.
Guess what you will see when using InputRoot.XML.*[LAST] ?
Right ! it will point to an unamed entry in the XML tree containing the last <cr><lf>
So, what does work is this much longer version
Code: |
DECLARE cnt INTEGER;
SET cnt = CARDINALITY(InputRoot.XML.*[]);
WHILE FIELDNAME(InputRoot.XML.*[cnt]) = '' DO
SET cnt = cnt - 1;
END WHILE;
DECLARE in_Message REFERENCE TO InputRoot.XML.*[cnt]; |
Looks awfull, doesn't it ? there has to be beter way.
Ernest. |
|
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
|
|
|
|