Author |
Message
|
chibban |
Posted: Sat Sep 24, 2005 2:29 pm Post subject: Locate an Element in XML and Promote ESQL variable 2 SubFlow |
|
|
Novice
Joined: 01 Jun 2005 Posts: 14
|
Hi all,
I have 2 problems and I'm in need for help :
1
==
I'm looking for a function that gets XML and an Element name,
locates that element in the XML and returns it's value.
I heard that it can be done in Java and XPath - so I can call it in my
ESQL code, and it can also be done using tree traversal in pure ESQL.
Can any one post a code sample or give a link to such ?
2
==
Is there a way to promote ESQL variables to a SubFlow properties ?
Somthing like :
Code: |
LogInDb(%%systemName%%, timestamp, %%status%%); |
where the systemName and status are properties of the SubFlow ? _________________ Thanks,
Sivan |
|
Back to top |
|
 |
recallsunny |
Posted: Sun Sep 25, 2005 6:03 am Post subject: |
|
|
 Disciple
Joined: 15 Jun 2005 Posts: 163 Location: Massachusetts
|
use something like this for your Question 1:
Code: |
Set tmpVar = THE( Select ITEM I.elevalue FROM Root.XML.yourmsg AS I WHERE I.elename = 'your element name here')
|
You could do also do this in Java/Xpath, however I donot think this simple task needs an external Java call (JVM call might have performance affect).
The answer to Question 2: Not in Version 5.0 of message broker. You cannot promote ESQL variables. |
|
Back to top |
|
 |
jfluitsm |
Posted: Sun Sep 25, 2005 10:07 pm Post subject: |
|
|
Disciple
Joined: 24 Feb 2002 Posts: 160 Location: The Netherlands
|
Question 2. This is announced for WMB v6.0 _________________ Jan Fluitsma
IBM Certified Solution Designer WebSphere MQ V6
IBM Certified Solution Developer WebSphere Message Broker V6 |
|
Back to top |
|
 |
chibban |
Posted: Sun Oct 02, 2005 12:48 am Post subject: |
|
|
Novice
Joined: 01 Jun 2005 Posts: 14
|
Hey all !
First of all thanks for the fast reply.
Secondly, I tried using the select u mentioned but it doesn't work.
My XML tree looks like this :
Code: |
Envelope
Body
InsertBug
caseID
type=number
1111
caseDesc
type=char
"this is my case"
... |
How do I write SELECT to get the 1111?
Maybe somthing like :
Code: |
DECLARE answer AS CHARACHTER;
SET answer = THE(SELECT ITEM I.??? FROM InputBody AS I
WHERE I.???);
|
I'll apricciate an answer with detailed example (including the XML tree) since I couldn't use the SELECT clause to get any data from XML...  _________________ Thanks,
Sivan |
|
Back to top |
|
 |
JT |
Posted: Sun Oct 02, 2005 8:56 am Post subject: |
|
|
Padawan
Joined: 27 Mar 2003 Posts: 1564 Location: Hartford, CT.
|
|
Back to top |
|
 |
chibban |
Posted: Sun Oct 02, 2005 1:19 pm Post subject: |
|
|
Novice
Joined: 01 Jun 2005 Posts: 14
|
I think that either I don't understand u or I wasn't clear about what I'm looking for.
I want to write a generic function, that recieve 2 arguments :
XML tree and element name
and retrieve the corelated element value.
For example, with the given XML I posted before and the name 'caseID'
this function should return the value '1111'.
the command :
Code: |
SET answer = valueOfElement(InputRoot, 'caseID'); |
should SET answer to be '1111'.
The main thing is that I don't know where the elemend resides whithin the XML, I only get a name, and I need to search it and return it's value.
I succeeded doing so with ASBITSTREAM and POSITION (parsing the XML)
but I thoght there is a better way with the SELECT cluase.
Is there ? _________________ Thanks,
Sivan |
|
Back to top |
|
 |
vinbud117 |
Posted: Sun Oct 02, 2005 11:26 pm Post subject: |
|
|
Acolyte
Joined: 22 Jul 2005 Posts: 61
|
with respect to your second question.... You can set the values to Environment.Variables.xxx and then use these environment variables in the subflow.
Regarding the first question, i doubt if there is any command to search for an element... |
|
Back to top |
|
 |
JT |
Posted: Mon Oct 03, 2005 8:23 am Post subject: |
|
|
Padawan
Joined: 27 Mar 2003 Posts: 1564 Location: Hartford, CT.
|
Didn't mean to confuse you. What I intended for you to understand is that you could accomplish what you're looking for in either of two ways:
Quote: |
DECLARE inputRootRef REFERENCE TO InputRoot.XML.Envelope.Body.InsertBug;
DECLARE answer CHARACTER;
CALL valueOfElement(inputRootRef, 'caseID', answer);
CREATE PROCEDURE valueOfElement(IN inputRootRef REFERENCE, IN tagName CHARACTER, OUT answer CHARACTER) BEGIN
SET answer = THE (SELECT ITEM I FROM inputRootRef.{tagName} AS I);
END; |
or in a simpler fashion....
Quote: |
DECLARE inputRootRef REFERENCE TO InputRoot.XML.Envelope.Body.InsertBug;
DECLARE answer CHARACTER;
CALL valueOfElement(inputRootRef, 'caseID', answer);
CREATE PROCEDURE valueOfElement(IN inputRootRef REFERENCE, IN tagName CHARACTER, OUT answer CHARACTER) BEGIN
SET answer = inputRootRef.{tagName};
END; |
|
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Oct 03, 2005 8:26 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
{} only supports one level. It does not support, for example, A.B.C, just A.
One might be able to code a select statement, where the where clause used FIELDNAME.
Or one can write the standard loop over the children. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
wschutz |
Posted: Mon Oct 03, 2005 9:14 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
I've done this in broker V6 with a java compute node and xpath:
Code: |
String s = inMsg.evaluateXpath("string(//item2find)");
|
will find "item2find" anywhere in the input tree. I haven't tried it
in broker v5. _________________ -wayne |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Oct 03, 2005 9:22 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
evaluateXpath appears to only exist in the v6 API. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
wschutz |
Posted: Mon Oct 03, 2005 9:29 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
Quote: |
evaluateXpath appears to only exist in the v6 API.
|
Its a good thing I never tried it then  _________________ -wayne |
|
Back to top |
|
 |
chibban |
Posted: Sat Oct 15, 2005 8:58 am Post subject: |
|
|
Novice
Joined: 01 Jun 2005 Posts: 14
|
Finally I decided to search the XML as a string :
I used AsBitStream function to "flaten" the tree into string, and then used the POSITION function to locate the element inside that string. Then I parsed the part that I wanted (the value of the element).
I don't have V6, and I figured that parsing has better performance then :
1) External java call (to use XPATH).
2) Recursive tree traversal.
Thanks for the help ! _________________ Thanks,
Sivan |
|
Back to top |
|
 |
|