Author |
Message
|
narendra |
Posted: Tue Oct 15, 2002 1:44 pm Post subject: How to get XML root node name in ESQL |
|
|
Apprentice
Joined: 04 Jun 2002 Posts: 26
|
HI gurus
How can I get the name of the root element of the input XML message in the compute node
Thanks in advance
Narendra  |
|
Back to top |
|
 |
lung |
Posted: Tue Oct 15, 2002 5:32 pm Post subject: |
|
|
 Master
Joined: 27 Aug 2002 Posts: 291 Location: Malaysia
|
Narendra,
lillo has posted the answer to this question in several topics in this forum.
Anyway, the answer to your question is this
Remember that the last element in the message will always be the root element, but the first element in the message may not be the root element.
 _________________ lung |
|
Back to top |
|
 |
narendra |
Posted: Wed Oct 16, 2002 6:43 am Post subject: |
|
|
Apprentice
Joined: 04 Jun 2002 Posts: 26
|
Lung
I do not get nothing with this. Empty string.
Narendra |
|
Back to top |
|
 |
lung |
Posted: Wed Oct 16, 2002 5:11 pm Post subject: |
|
|
 Master
Joined: 27 Aug 2002 Posts: 291 Location: Malaysia
|
Narendra,
What are you trying to do here? Are you trying to put the root name of an XML message into a variable?
In terms of referencing, *[LAST] will work  _________________ lung |
|
Back to top |
|
 |
narendra |
Posted: Thu Oct 17, 2002 10:22 am Post subject: |
|
|
Apprentice
Joined: 04 Jun 2002 Posts: 26
|
Hi Lung
You are right.
I put various topics on the input queue. The root element of the input message gives me the name of the TOPIC.
I tried the way you adviced me. But it return me empty string.
Please let me know, if i am missing any thing.
Thanks in advnce
Narendra |
|
Back to top |
|
 |
lung |
Posted: Thu Oct 17, 2002 6:09 pm Post subject: |
|
|
 Master
Joined: 27 Aug 2002 Posts: 291 Location: Malaysia
|
Code: |
SET A = FIELDNAME(InputBody.*[LAST]); |
Hope this works  _________________ lung |
|
Back to top |
|
 |
ernest-ter.kuile |
Posted: Thu Oct 17, 2002 11:37 pm Post subject: |
|
|
 Apprentice
Joined: 13 May 2002 Posts: 49 Location: KLM Holland
|
narendra wrote: |
Lung
I do not get nothing with this. Empty string.
Narendra |
This is because the XML parser interlaces the XML tree with the formating characters found in the XML message. You have a CR a LF or an blank at the end of the xml message.
the only way I found to get the correct root XML element is this :
Code: |
DECLARE cnt INTEGER;
SET cnt = CARDINALITY(InputRoot.XML.*[]);
SET A = FIELDNAME(InputRoot.XML.*[cnt]);
IF A = '' THEN
SET A = FIELDNAME(InputRoot.XML.*[cnt - 1]);
END IF; |
Actually, I would greatly appriciate if somebody provided a beter way, as I'm not sure this works in all cases, but in my tests this works if your XML is followed by CR, LF, TABs, etc...
I suspect that the root XML element will always be either the LAST or the LAST - 1. unfortunatly ...
Code: |
SET A = FIELDNAME(InputBody.*[LAST - 1]); |
... does not work. |
|
Back to top |
|
 |
narendra |
Posted: Tue Oct 22, 2002 7:45 am Post subject: |
|
|
Apprentice
Joined: 04 Jun 2002 Posts: 26
|
Hi Lung Guru
The trick worked. Thank you so much
Narendra  |
|
Back to top |
|
 |
|