Author |
Message
|
OMG |
Posted: Wed Feb 29, 2012 11:35 pm Post subject: Trouble in accessing attribute values using XPATH in WMB |
|
|
 Novice
Joined: 20 Feb 2012 Posts: 18
|
I am not able to access the attribute values from the a XML message using XPATH.
The example xml message is like
Code: |
<Transaction CancelFlag="false" TrainingModeFlag="false" OfflineFlag="false">
<RetailStoreID>0210</RetailStoreID>
<WorkstationID>0052</WorkstationID>
<NumberOfStrings>0011</NumberOfStrings>
<SequenceNumber>1253</SequenceNumber>
</Transaction> |
I have to access the flag values like CancelFlag or OfflineFlag etc.
Any help will be appreciated. |
|
Back to top |
|
 |
OMG |
Posted: Wed Feb 29, 2012 11:36 pm Post subject: Re: Trouble in accessing attribute values using XPATH in WMB |
|
|
 Novice
Joined: 20 Feb 2012 Posts: 18
|
OMG wrote: |
I am not able to access the attribute values from the a XML message using XPATH.
The example xml message is like
Code: |
<Transaction CancelFlag="false" TrainingModeFlag="false" OfflineFlag="false">
<RetailStoreID>0210</RetailStoreID>
<WorkstationID>0052</WorkstationID>
<NumberOfStrings>0011</NumberOfStrings>
<SequenceNumber>1253</SequenceNumber>
</Transaction> |
I have to access the flag values like CancelFlag or OfflineFlag etc.
Any help will be appreciated. |
|
|
Back to top |
|
 |
OMG |
Posted: Wed Feb 29, 2012 11:41 pm Post subject: Re: Trouble in accessing attribute values using XPATH in WMB |
|
|
 Novice
Joined: 20 Feb 2012 Posts: 18
|
Please share the syntax to extract this attribute values in MbElement using XPATH.
 |
|
Back to top |
|
 |
Esa |
Posted: Wed Feb 29, 2012 11:53 pm Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Did you try /Transaction@CancelFlag?
You can find several XPath tutorials by googling. |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu Mar 01, 2012 12:03 am Post subject: Re: Trouble in accessing attribute values using XPATH in WMB |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
OMG wrote: |
Please share the syntax to extract this attribute values in MbElement using XPATH.
 |
Please show a little patience. This forum is manned by volunteers who have their 'Day Job' to to as well as answering posts.
Posting at 07:35 (UK Time) and then posting again only a few minutes later will not speed up any replies you may get. This particular time is a 'dead' spot for many of the regular posters here. In the US most are fast asleep and in Europe, people are just going to work.
We do like to see evidence that people have tried a few things and even searched here for previous related posts before posting themselves.
Your post gave no hint that you had tried anything at all.
If you don't tell us what you have tried then you might well get a whole raft of suggestions that match what you have tried. That is not good. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
OMG |
Posted: Thu Mar 01, 2012 12:22 am Post subject: |
|
|
 Novice
Joined: 20 Feb 2012 Posts: 18
|
@Esa :
yes I have used the following statement as
Code: |
vCancelFlag = (inputBody.getFirstElementByPath("./Transaction@CancelFlag")).getValueAsString(); |
But it's throwing NullPointerException.
@smdavies99:
Actually i was trying to edit my first post but after editing while i submit it, it was submitted as a reply though i didn't add any reply on my own post! |
|
Back to top |
|
 |
adubya |
Posted: Thu Mar 01, 2012 12:32 am Post subject: |
|
|
Partisan
Joined: 25 Aug 2011 Posts: 377 Location: GU12, UK
|
|
Back to top |
|
 |
OMG |
Posted: Thu Mar 01, 2012 12:45 am Post subject: |
|
|
 Novice
Joined: 20 Feb 2012 Posts: 18
|
hi adubya
vCancelFlag = (inputBody.getFirstElementByPath("./Transaction/@CancelFlag")).getValueAsString(); this one is also throwing the same NullPointerException.  |
|
Back to top |
|
 |
Esa |
Posted: Thu Mar 01, 2012 12:48 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
MbElement.getFirstElementByPath() is not deprecated, it's MbElement.getAllElementsByPath() that is deprecated.
Your link points to WMB V6.0.0 InfoCenter. V 6.0.0 is out of support.
@OMG: are you sure it's not inputBody that points to null?
Last edited by Esa on Thu Mar 01, 2012 12:50 am; edited 1 time in total |
|
Back to top |
|
 |
adubya |
Posted: Thu Mar 01, 2012 12:49 am Post subject: |
|
|
Partisan
Joined: 25 Aug 2011 Posts: 377 Location: GU12, UK
|
Break up your statement then, i.e get the inputBody, then access the CancelFlag attribute, then get it's value as individual statements. See which one is returning null and do some digging. |
|
Back to top |
|
 |
mqsiuser |
Posted: Thu Mar 01, 2012 12:50 am Post subject: |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
OMG wrote: |
vCancelFlag = (inputBody.getFirstElementByPath("./Transaction/@CancelFlag")).getValueAsString(); this one is also throwing the same NullPointerException.  |
have you downloaded XPathBuilder!? Do that! Use that!
For development/testing start with using "//" ("//Transaction/@CancelFlag") (and look into XPathBuilder) if it returns (at least) one node (element). (Later remove the "search-all" ("//") with "/")
Do you use XMLNSC parser ?!... look in the debugger (of Broker) and verify that you message got properly parsed in. You need to setup your dev environment a bit. Have you set a break point and successfully stepped into it? Do you see that the message is properly dispayed in the debug-view?
The xPath expression here seems fine, likely something else is going wrong. _________________ Just use REFERENCEs |
|
Back to top |
|
 |
adubya |
Posted: Thu Mar 01, 2012 1:03 am Post subject: |
|
|
Partisan
Joined: 25 Aug 2011 Posts: 377 Location: GU12, UK
|
@Esa - yes, naughty me. Must check links before posting  |
|
Back to top |
|
 |
OMG |
Posted: Thu Mar 01, 2012 1:25 am Post subject: |
|
|
 Novice
Joined: 20 Feb 2012 Posts: 18
|
Hi All,
I have resolved the issue using the following code
Code: |
vCancelFlag = (inputBody.getFirstElementByPath("./Transaction/CancelFlag")).getValueAsString(); |
no '@' is needed here because after parsing the XML attributes became the child of the root element.
Thanks everyone for the help!! |
|
Back to top |
|
 |
vishnurajnr |
Posted: Thu Mar 01, 2012 10:24 pm Post subject: |
|
|
 Centurion
Joined: 08 Aug 2011 Posts: 134 Location: Trivandrum
|
Thanks for updating this info!  |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Mar 02, 2012 10:11 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
OMG wrote: |
Hi All,
I have resolved the issue using the following code
Code: |
vCancelFlag = (inputBody.getFirstElementByPath("./Transaction/CancelFlag")).getValueAsString(); |
no '@' is needed here because after parsing the XML attributes became the child of the root element.
Thanks everyone for the help!! |
Could that be because you moved it into the Environment without setting a parser??  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|