|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
MbXPath Problem |
« View previous topic :: View next topic » |
Author |
Message
|
deepnair |
Posted: Tue Apr 03, 2012 2:22 pm Post subject: MbXPath Problem |
|
|
Apprentice
Joined: 07 Feb 2012 Posts: 35
|
Im trying for an XPath in my java code, the first one below i.e. getFirstElementByPath works and returns the value but when i xpath, its not working, the node list size returned is 0.
The below code works
Code: |
outBody.getFirstElementByPath("./se:Envelope/se:Header/aa:Action").getValue().toString()
|
But when I try an xpath it does not work
Code: |
MbXPath xPath = new MbXPath("./se:Envelope/se:Header/aa:Action");
xPath.addNamespacePrefix("se",
"http://www.w3.org/2003/05/soap-envelope");
xPath.addNamespacePrefix("def", "http://def.com/envelope");
xPath.addNamespacePrefix("aa", "http://aa.com/aaV001");
List listHeader = (List) outBody.evaluateXPath(xPath);
log.debug("# of elements is ** - " + listHeader.size());
|
Why is xpath not pointing to the element though it exists ?
Thanks,
Deep Nair |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Apr 03, 2012 7:43 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Have you taken a user trace to see why the xpath is not working?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mqsiuser |
Posted: Tue Apr 03, 2012 8:50 pm Post subject: Re: MbXPath Problem |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
Code: |
outBody.getFirstElementByPath("./se:Envelope/se:Header/aa:Action").getValue().toString()
MbXPath xPath = new MbXPath("./se:Envelope/se:Header/aa:Action"); |
1. It says "get by path" and not "get by xpath"
2 . Read w3schools (the parts on xPath), and then the w3c standard/recommendation on xpath
3. Use an xpath editor or xml editor, e.g. oXygen (rightclick there on an xml element/attribute and select "copy XPath")
4. Try removing the leading dot (.)
5. Recheck if your namespaces are correctly set, e.g. you are defining "def" (seems like for envelope), but then use "se:" (for the envelope)
6. Indicate your (exact) intentions (this will help the parser to perform better):
Code: |
MbXPath("/se:Envelope[1]/se:Header[1]/aa:Action[1]"); |
If nothing matches your xPath expression the result (node set) will just be empy (and you will not have an exception/error)... so if there really/actually should be something (returning from your query) I suppose it is up to you to throw an exception (base on a check for "is empty" on the xpath-result-set). _________________ Just use REFERENCEs |
|
Back to top |
|
 |
zhumingvictor |
Posted: Fri May 10, 2013 7:43 am Post subject: |
|
|
Novice
Joined: 10 May 2013 Posts: 17
|
Hi, I am having the same problem. Did you get it solved? |
|
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
|
|
|
|