Author |
Message
|
duffMan |
Posted: Wed Oct 08, 2003 6:52 pm Post subject: Referencing XML Attributes |
|
|
 Voyager
Joined: 03 Jun 2002 Posts: 75
|
Hi,
I am trying to "efficiently" reference an XML tree that may look something like:
Code: |
<XMLRoot>
<InputFields>
<abc zzz="A">value1</abc>
<abc zzz="B">value2</abc>
<abc zzz="C">value3</abc>
...
</InputFields>
</XMLRoot> |
- as you can see the aggregate "InputFields" contains only one child element, namely "abc" which repeats, and abc contains an xml attribute zzz which contains some data (which happens to be unique accross all zzz attributes on abc)
As an example,
I need to extract the value contained in element "abc" where "zzz"="C".
I don't want to scan because in the real-life example there will be hundreds of "abc" siblings for which I need to reference many times over.
I don't want to use an index such as SET myValue=abc[3], because abc[3] may not actually be zzz="C", should zzz="A" or zzz="B" not exist in a particular instance of the XML.
So I get back to the question: how do I effeciently, if at all possible, reference an XML element by the value of one of it's attributes?
Thanks for any ideas. |
|
Back to top |
|
 |
kirani |
Posted: Wed Oct 08, 2003 7:04 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Well, I can think of these options,
a) scan the tree for required element and attribute.
b) use SELECT statement to select value from the XML tree. _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
duffMan |
Posted: Wed Oct 08, 2003 7:22 pm Post subject: |
|
|
 Voyager
Joined: 03 Jun 2002 Posts: 75
|
You woudn't mind showing such as XML statement with an XML attribute in the where clause?
I am also assuming that a SELECT statement will result in a scan internally at run-time, but it would look much cleaner code-wise.
Thanks. |
|
Back to top |
|
 |
kirani |
Posted: Wed Oct 08, 2003 11:03 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
That's correct, using SELECT statement will also internally scan the elements. Here is the sample code,
Code: |
SET Val = THE ( SELECT ITEM T from InputRoot.XML.XMLRoot.InputFields.abc[] as T WHERE T.(XML.Attribute)zzz = 'C')
|
_________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
kimbert |
Posted: Thu Oct 09, 2003 1:07 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I assume you are using the XML domain?
In the MRM domain, this style of XML is known as 'XMLElementAttrId'.
(which means that the elements are identified by one of their attributes, instead of by their tag name)
If you modelled your message using this XML rendering style for the 'InputFields' element, you would be able to create a much simpler message tree.
InputBody
InputFields
A
B
C
Then you would be able to write ESQL like this:
SET Val = InputBody.InputFields.C
Using the MRM domain generally results in simpler message trees, and therefore simpler ESQL. Message processing is a little slower, though.
Let me know if you're interested. |
|
Back to top |
|
 |
duffMan |
Posted: Thu Oct 09, 2003 4:02 am Post subject: |
|
|
 Voyager
Joined: 03 Jun 2002 Posts: 75
|
Thanks Kirani for the SQL...I'll see how it performs.
Thanks kimbert, I'll give that a try too. I do have a DTD for that XML which I'll attempt to import into MRM. |
|
Back to top |
|
 |
kimbert |
Posted: Fri Oct 10, 2003 12:54 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
To avoid any confusion...importing the DTD will not automatically set up your MRM message set in the way I described - it should be a good start, though, because it will create all your elements and organise them into the right structure. |
|
Back to top |
|
 |
|