Author |
Message
|
Seb |
Posted: Sun Jan 23, 2011 1:25 am Post subject: No result from evaluateXPath |
|
|
Apprentice
Joined: 27 Mar 2009 Posts: 41
|
Hi,
I am opening this topic for one of our developers, who is struggling with the evaluateXPath function. However, using XMLSpy it seems to be valid v1.0 statement.
This is an exemplary message:
Code: |
<Element01>
<Element02>
<Element03>sun</Element03>
<Element04>
<Element05>hello</Element05>
</Element04>
</Element02>
<Element02>
<Element03>rain</Element03>
<Element04>
<Element05>good bye</Element05>
</Element04>
</Element02>
</Element01>
|
He tries to first test the value of a child element before he gets the value of the ancestor:
/Element01/Element02/Element04/Element05[text() = 'hello']/parent::node()/parent::node()/Element03
I couldn't see anything wrong or a way of reconstructing the statement. Hope someone can help.
Thanks,
Seb |
|
Back to top |
|
 |
mqjeff |
Posted: Sun Jan 23, 2011 7:22 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I'm not entirely sure that text() is the right thing to get the value of the element. But I've not double-checked that intuition against the Broker XPath documentation. |
|
Back to top |
|
 |
rekarm01 |
Posted: Sun Jan 23, 2011 8:58 am Post subject: Re: No result from evaluateXPath |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
Seb wrote: |
Code: |
/Element01/Element02/Element04/Element05[text() = 'hello']/parent::node()/parent::node()/Element03 |
|
XPath models an XML document as a tree of XML nodes; text nodes are always children of element nodes. MbXPath operates against a tree of MbElements; whether text nodes are children of element nodes depends on the tree structure. A Trace node would illustrate the tree structure.
Compare this:
Code: |
/* XPath: ".../Element05[text()='hello']/..." */
MbElement(type=TYPE_NAME, name="Element05")
MbElement(type=TYPE_VALUE, value="hello") |
with this:
Code: |
/* XPath: ".../Element05[self::node()='hello']/..." */
MbElement(type=TYPE_NAME_VALUE, name="Element05", value="hello") |
For the second example, the complete XPath expression would be:
Code: |
/Element01/Element02/Element04/Element05[self::node()='hello']/parent::node()/parent::node()/Element03 |
or abbreviated:
Code: |
/Element01/Element02/Element04/Element05[.='hello']/../../Element03 |
or refactored:
Code: |
/Element01/Element02[Element04/Element05='hello']/Element03 |
|
|
Back to top |
|
 |
Esa |
Posted: Sun Jan 23, 2011 9:04 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Regardles of if the syntax of the xsl sample is right or wrong, you get no results because it is pointing to a nonexistent element.
/Element01/Element02 does not have a child called Element03. |
|
Back to top |
|
 |
Esa |
Posted: Sun Jan 23, 2011 9:06 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Yes it has. I need new glasses. |
|
Back to top |
|
 |
rekarm01 |
Posted: Sun Jan 23, 2011 6:58 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
Esa wrote: |
Regardless of if the syntax of the xsl sample ... |
Typo? On a side note, XSL Transformations supports a subset of XPath expressions as matching patterns, allowing only child and attribute axis specifiers. "parent::node()" would not be part of a valid XSLT matching pattern. |
|
Back to top |
|
 |
bsiggers |
Posted: Mon Jan 24, 2011 8:57 am Post subject: Isolation? |
|
|
Acolyte
Joined: 09 Dec 2010 Posts: 53 Location: Vancouver, BC
|
You may want to test your XML and XPATH outside of broker - there are lots of interactive tools online if you don't happen to have something like XMLSpy.
http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm
This way you can isolate if it's an XPATH expression issue or something wrong in the way that you're working with/interpreting the results. |
|
Back to top |
|
 |
Seb |
Posted: Thu Jan 27, 2011 3:59 pm Post subject: |
|
|
Apprentice
Joined: 27 Mar 2009 Posts: 41
|
Hi,
just want to say thanks!
rekarm01's solution worked with a couple of slight modifications due to our more complex IFW XML structures.
@bsiggers: That was the weird thing, the developer was actually constructing the xpath statements in XML Spy and they worked fine, but WMB didn't get to the same result.
Anyway, problem solved and I learned how to better construct the xpath statements as well.
Thanks again,
Seb |
|
Back to top |
|
 |
|