Author |
Message
|
brokerdevel |
Posted: Fri May 28, 2010 10:42 am Post subject: Accessing xml elements |
|
|
Newbie
Joined: 28 May 2010 Posts: 6
|
Hiya,
I am having trouble accessing certain elements in a simple xml message. Coudl some pls help.
here is the tree.
<Message>
<A>
<B>
<AdditionalFlds>
<Field name="f1">abc</Field>
<Field name="f2">def</Field>
<AdditionalFlds>
</Message>
I am trying to access f1 as follows without any luck
SET ret = OutputRoot.XMLNSC.Message.(XMLNSC.Value)f1 |
|
Back to top |
|
 |
Vitor |
Posted: Fri May 28, 2010 11:23 am Post subject: Re: Accessing xml elements |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
brokerdevel wrote: |
I am trying to access f1 as follows without any luck
SET ret = OutputRoot.XMLNSC.Message.(XMLNSC.Value)f1 |
Did you even look at the ESQL manual? Or your message? Or an XML manual?
Looking at the message, I'd try:
Code: |
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Attribute).name |
Untried, untested and a user trace with a Trace node would have helped you immensely. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
brokerdevel |
Posted: Fri May 28, 2010 11:50 am Post subject: |
|
|
Newbie
Joined: 28 May 2010 Posts: 6
|
Thanks Vit.
I tried.
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Attribute)name
But it returns 'f1'. I want to get the value of the field that is 'abc' |
|
Back to top |
|
 |
Vitor |
Posted: Fri May 28, 2010 11:58 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
brokerdevel wrote: |
But it returns 'f1'. I want to get the value of the field that is 'abc' |
Well you said you wanted "f1" in your original post!
Have a little experiment and see if you can merger my corrections with your original attempt & get the value you're looking for. It's really not that hard.
My advice on tracing holds. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
napier |
Posted: Fri May 28, 2010 11:58 am Post subject: |
|
|
 Apprentice
Joined: 09 Oct 2007 Posts: 48 Location: USA
|
|
Back to top |
|
 |
brokerdevel |
Posted: Tue Jun 01, 2010 6:03 am Post subject: |
|
|
Newbie
Joined: 28 May 2010 Posts: 6
|
Sorry guys, I am unable to retrive that element.
I tried content but then should I pass value to it?
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.content)name ?
I did try lot of experimentation but no luck. I am new to XML level access. Can someone pls help. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jun 01, 2010 7:22 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
brokerdevel wrote: |
I did try lot of experimentation but no luck. |
Post all your experiments and their results. There's no point us suggesting something that's already failed to give the results you need. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
brokerdevel |
Posted: Tue Jun 01, 2010 7:30 am Post subject: |
|
|
Newbie
Joined: 28 May 2010 Posts: 6
|
Vitor,
Here are all those I tried...
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Attribute)value
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Field)value
SET ret=FIELDVALUE(InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Attribute)f1
SET ret=FIELDVALUE(InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Field)f1
All the above returns null. The following actually returned the field name 'f1'
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Attribute)name
So element access path seems to be correct. but the value access is having problem |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jun 01, 2010 8:08 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
brokerdevel wrote: |
So element access path seems to be correct. but the value access is having problem |
No it's not - you're having a problem reading your own XML. There's no element called "value" in the XML so of course you don't get a result. No matter how many combinations of descriptor you use. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jun 01, 2010 8:10 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
brokerdevel wrote: |
Vitor,
Here are all those I tried...
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Attribute)value
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Field)value
SET ret=FIELDVALUE(InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Attribute)f1
SET ret=FIELDVALUE(InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Field)f1
All the above returns null. The following actually returned the field name 'f1'
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Attribute)name
So element access path seems to be correct. but the value access is having problem |
The value access might have a problem because VALUE is a reserved ESQL word.
Try putting "value" (with the quotes). If double quotes don't work try single quotes. This should solve it.
Code: |
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1].(XMLNSC.Attribute)"value" |
 _________________ MQ & Broker admin |
|
Back to top |
|
 |
brokerdevel |
Posted: Tue Jun 01, 2010 8:19 am Post subject: |
|
|
Newbie
Joined: 28 May 2010 Posts: 6
|
Vitor,
no, there is no element called 'value'. I am using it as verb to retrive the value of that element. (i saw you using 'name' to retrive the name so ..)
Here is the message tree...
<Message>
<AdditionalFlds>
<Field name="f1">abc</Field>
<Field name="f2">def</Field>
<AdditionalFlds>
</Message>
I want to retrive value of 'f1' that is 'abc'. the message tree is complete and has proper values. I confirmed it using visual debugger. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jun 01, 2010 8:27 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
OOPS...
To retrieve abc try:
Code: |
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1]; |
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jun 01, 2010 8:42 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
brokerdevel wrote: |
no, there is no element called 'value'. I am using it as verb to retrive the value of that element. (i saw you using 'name' to retrive the name so ..) |
No I didn't - the attribute in your document is called "name"
Try looking at the document then try reading the ESQL manual!! _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
brokerdevel |
Posted: Tue Jun 01, 2010 8:52 am Post subject: |
|
|
Newbie
Joined: 28 May 2010 Posts: 6
|
Thanks a lot fjb_saper. it worked.
Vitor, yeah i agree, i need a lot of learning to do on ESQL XML. |
|
Back to top |
|
 |
fatherjack |
Posted: Tue Jun 01, 2010 9:13 am Post subject: |
|
|
 Knight
Joined: 14 Apr 2010 Posts: 522 Location: Craggy Island
|
fjb_saper wrote: |
OOPS...
To retrieve abc try:
Code: |
SET ret=InputRoot.XMLNSC.Message.AdditionalFlds.Field[1]; |
Have fun  |
Simple but effective. Although I did kinda think the OP was trying to do something marginally more complex like trying to retrieve the value of the element 'Field' whose attribute 'name' had a value of 'f1', rather than just get the first element, knowing full well that this matched his criteria.
An even simpler solution would be
 _________________ Never let the facts get in the way of a good theory. |
|
Back to top |
|
 |
|