Author |
Message
|
oli |
Posted: Wed Feb 06, 2008 3:26 am Post subject: Question about XPath |
|
|
Acolyte
Joined: 14 Jul 2006 Posts: 68 Location: Germany
|
Hi all,
I have the following behaviour in my Java Plug-in node when the Plug-in node gets a message, e.g. coming from a MQInputNode with message domain "XMLNS":
Code: |
theMbMessageAssembly().getMessage().getRootElement().getFirstChild().getNextSibling().getNextSibling().getName() |
returns "XMLNS" (as expected)
Code: |
theMbMessageAssembly().getMessage().getRootElement().evaluateXPath("XMLNS") |
returns an empty list
Code: |
theMbMessageAssembly().getMessage().getRootElement().evaluateXPath("*") |
returns a list with two elements "Properties" and "MQMD"
Why is the "XMLNS" element not accessible using XPath?
I'm using MB V6.1.0.1
Thanks,
Oli |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Feb 06, 2008 3:48 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Possibly because you are looking at OutputRoot instead of InputRoot?
By the way I would not go for first child next next ... You should use last child as the parser should always be the last child of Root.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
oli |
Posted: Wed Feb 06, 2008 4:00 am Post subject: |
|
|
Acolyte
Joined: 14 Jul 2006 Posts: 68 Location: Germany
|
Hi fjb_saper,
Quote: |
Possibly because you are looking at OutputRoot instead of InputRoot |
I don't think that this is the problem, because the getLastChild() on the root element returns the element, but the evaluateXPath() doesn't.
The MbMessageAssembly is the one the plug-in node get's in it's evaluate() method.
Any other ideas?
Thanks,
Oli |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Feb 06, 2008 4:12 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
oli wrote: |
Hi fjb_saper,
Quote: |
Possibly because you are looking at OutputRoot instead of InputRoot |
I don't think that this is the problem, because the getLastChild() on the root element returns the element, but the evaluateXPath() doesn't.
The MbMessageAssembly is the one the plug-in node get's in it's evaluate() method.
Any other ideas?
Thanks,
Oli |
Recheck your java compute node code... (theMbMessageAssembly)
I believe at some point you create the OutputRoot by assigning a new value to an object of the MbMessageAssembly class.
So just the fact that your object is of that class doesn't tell me whether you're looking at InputRoot or OutputRoot.... Your result would be consistent with looking at OutputRoot before you have set any parsers... _________________ MQ & Broker admin |
|
Back to top |
|
 |
oli |
Posted: Wed Feb 06, 2008 6:25 am Post subject: |
|
|
Acolyte
Joined: 14 Jul 2006 Posts: 68 Location: Germany
|
Sorry, but I cannot solve the problem.
In my opinion it cannot be a problem with InputRoot or anything else. At the same location in the code of my Java Plug-in node
Code: |
theMessageAssembly.getMessage().getRootElement().evaluateXPath("XMLNS") |
does not return a MbElement
whereas the call
Code: |
theMessageAssembly.getMessage().getRootElement().getFirstElementByPath("XMLNS") |
returns the MbElement.
What's going wrong here, any more ideas?
Thanks |
|
Back to top |
|
 |
kimbert |
Posted: Wed Feb 06, 2008 7:11 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Have you tried this?
Code: |
getFirstElementByPath("/XMLNS") |
|
|
Back to top |
|
 |
oli |
Posted: Wed Feb 06, 2008 11:20 am Post subject: |
|
|
Acolyte
Joined: 14 Jul 2006 Posts: 68 Location: Germany
|
The
Code: |
getFirstElementByPath("XMLNS") |
works, but the
Code: |
evaluateXPath("XMLNS") |
doesn't, and that's my problem
In my opinion the 2 method calls must return the same MbElement ...
Further tips are appreciated. |
|
Back to top |
|
 |
kimbert |
Posted: Thu Feb 07, 2008 2:20 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
OK - I had to ask a colleague about this. Here's the reply:
Quote: |
The answer begins to emerge somewhere aound your tenth reading of the XPath spec .
The brief answer is that any nametest ("XMLNS" in this example) will match any element node of that name (section 2.3). However, the "XMLNS" node is a root node, not an element node (section 5.1). Therefore it doesn't match.
By default, the ( message broker ) XPath engine defines its 'root' to be the domain syntax element for the message payload (i.e. the equivalent of message.getRootElement().getLastChild()). This allows XPath expressions to be used without having to worry about broker-specific semantics (headers/domains). It is possible to assign any definition of 'root node' to the XPath engine by using the alternate MbXPath constructor which takes an MbElement as its second parameter. If you set this to message.getRootElement(), your expression will work.
Don't compare this behaviour to the old getFirstElementByPath() method. That doesn't use XPath.
|
Looks as if you need to create an MbXPath object as suggested above, and use that for all queries against your message tree. |
|
Back to top |
|
 |
oli |
Posted: Thu Feb 07, 2008 4:42 am Post subject: |
|
|
Acolyte
Joined: 14 Jul 2006 Posts: 68 Location: Germany
|
Hi kimbert,
thanks a lot for your help. The solution with the MbXPath seems to work for me, although I don't understand exactly why
Oli |
|
Back to top |
|
 |
|