|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Help with accessing XML Elements based on their attributes |
« View previous topic :: View next topic » |
Author |
Message
|
sorn73 |
Posted: Fri Oct 07, 2005 4:34 am Post subject: Help with accessing XML Elements based on their attributes |
|
|
Novice
Joined: 24 Mar 2004 Posts: 24 Location: Sweden
|
Hello fellow WMBers!
I have a customer that recieves messages in a standardized XML format. The standard is apparently developed cross-organizations, so I have no control over the structure.
The people who designed the XML format are very fond of using attributes to tag data, so I have something like:
Code: |
<A>
<NAME type="first">John</NAME>
<NAME type="last">Doe</NAME>
</A> |
This bugs me, as I can't reference an element using a unique path. I would like to do
Code: |
SET SomeVar = FIELDVALUE( A.NAME.(XML.Attr)type='last' ); |
but that's just plain stupid. I also tried something like
Code: |
SET SomeVar[] = (SELECT I.NAME FROM A.*[] AS I WHERE I.NAME.(XML.Attr)type = 'last' ) ; |
but I can't get the syntax right. I have resorted to looping over the elements, checking the attribute values and setting a lot of pointers that I can use later, a solution that I find horrible.
Has anyone else seen this scenarion and solved in a more elegant way? |
|
Back to top |
|
 |
JT |
Posted: Fri Oct 07, 2005 5:31 am Post subject: |
|
|
Padawan
Joined: 27 Mar 2003 Posts: 1564 Location: Hartford, CT.
|
Try this:
Code: |
SET SomeVar = THE(SELECT ITEM I FROM A.NAME[] AS I WHERE I.(XML.Attr)type = 'last' ) |
|
|
Back to top |
|
 |
sorn73 |
Posted: Sun Oct 09, 2005 11:36 am Post subject: |
|
|
Novice
Joined: 24 Mar 2004 Posts: 24 Location: Sweden
|
Yay! This worked like a charm... With two minor glitches. First of all (XML.Attr) didn't work for some reason, I had to write (XML.Attribute)... Go figure. Also, I only wanted the fieldvalue and not the attributes, but wrapping the select in FIELDVALUE() didn't work, so I bounced via a dummy character value. |
|
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
|
|
|
|