ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Trouble in accessing attribute values using XPATH in WMB

Post new topic  Reply to topic Goto page 1, 2  Next
 Trouble in accessing attribute values using XPATH in WMB « View previous topic :: View next topic » 
Author Message
OMG
PostPosted: Wed Feb 29, 2012 11:35 pm    Post subject: Trouble in accessing attribute values using XPATH in WMB Reply with quote

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
View user's profile Send private message
OMG
PostPosted: Wed Feb 29, 2012 11:36 pm    Post subject: Re: Trouble in accessing attribute values using XPATH in WMB Reply with quote

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
View user's profile Send private message
OMG
PostPosted: Wed Feb 29, 2012 11:41 pm    Post subject: Re: Trouble in accessing attribute values using XPATH in WMB Reply with quote

Novice

Joined: 20 Feb 2012
Posts: 18

Please share the syntax to extract this attribute values in MbElement using XPATH.

Back to top
View user's profile Send private message
Esa
PostPosted: Wed Feb 29, 2012 11:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
smdavies99
PostPosted: Thu Mar 01, 2012 12:03 am    Post subject: Re: Trouble in accessing attribute values using XPATH in WMB Reply with quote

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
View user's profile Send private message
OMG
PostPosted: Thu Mar 01, 2012 12:22 am    Post subject: Reply with quote

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
View user's profile Send private message
adubya
PostPosted: Thu Mar 01, 2012 12:32 am    Post subject: Reply with quote

Partisan

Joined: 25 Aug 2011
Posts: 377
Location: GU12, UK

MBElement.getFirstElementByPath() is a deprecated method, you should really be using the XPath 1.0 methods.

http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r0m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Fac30390_.htm

If you persevere with the deprecated approach though, you might want to try

Code:
vCancelFlag = (inputBody.getFirstElementByPath("./Transaction/@CancelFlag")).getValueAsString();


Note the added "/" before the attribute selector.
Back to top
View user's profile Send private message Send e-mail
OMG
PostPosted: Thu Mar 01, 2012 12:45 am    Post subject: Reply with quote

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
View user's profile Send private message
Esa
PostPosted: Thu Mar 01, 2012 12:48 am    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

adubya wrote:
MBElement.getFirstElementByPath() is a deprecated method, you should really be using the XPath 1.0 methods.

http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r0m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Fac30390_.htm



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
View user's profile Send private message
adubya
PostPosted: Thu Mar 01, 2012 12:49 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
mqsiuser
PostPosted: Thu Mar 01, 2012 12:50 am    Post subject: Reply with quote

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
View user's profile Send private message
adubya
PostPosted: Thu Mar 01, 2012 1:03 am    Post subject: Reply with quote

Partisan

Joined: 25 Aug 2011
Posts: 377
Location: GU12, UK

@Esa - yes, naughty me. Must check links before posting
Back to top
View user's profile Send private message Send e-mail
OMG
PostPosted: Thu Mar 01, 2012 1:25 am    Post subject: Reply with quote

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
View user's profile Send private message
vishnurajnr
PostPosted: Thu Mar 01, 2012 10:24 pm    Post subject: Reply with quote

Centurion

Joined: 08 Aug 2011
Posts: 134
Location: Trivandrum

Thanks for updating this info!
Back to top
View user's profile Send private message Visit poster's website
fjb_saper
PostPosted: Fri Mar 02, 2012 10:11 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Trouble in accessing attribute values using XPATH in WMB
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.