AuthorDocumentController findNodesByXpath not returning expected values
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 45
- Joined: Wed May 23, 2012 11:20 am
AuthorDocumentController findNodesByXpath not returning expected values
I'm writing some code to find all <para/> nodes within a <paragraph/> node. However I'm retrieving all para nodes within the entire document.
I'm using the following code
However using the the console output I'm getting the following. The paragraph I'm using for the relative path is
However I'm getting the following para nodes returned.
I only expected "<para> (24, 40)" to be returned.
I'm using the following code
Code: Select all
final AuthorNode node = access.getDocumentController().getNodeAtOffset(offset);
final AuthorNode paragraphNode = DocumentUtils.getParagraphNode(node);
final AuthorNode[] paraNodes = access.getDocumentController().findNodesByXPath("//para", paragraphNode, true, true, true, true);
Code: Select all
<paragraph> (23, 41)
Code: Select all
[<para> (24, 40), <para> (45, 61), <para> (66, 88), <para> (89, 111), <para> (116, 138), <para> (139, 161), <para> (166, 188), <para> (189, 211), <para> (216, 238), <para> (239, 261), <para> (266, 288), <para> (289, 311), <para> (316, 332), <para> (345, 361), <para> (406, 422), <para> (446, 462), <para> (495, 511), <para> (528, 544), <para> (571, 587), <para> (592, 608)]
-
- Posts: 9449
- Joined: Fri Jul 09, 2004 5:18 pm
Re: AuthorDocumentController findNodesByXpath not returning expected values
Hi Neil,
This is how XPath expressions work, even when you interpret it relative to a node, if you use a // construct then the expression is interpreted as absolute.
For your case you should have simply used the expression para which would have returned all para's from that element.
You can test XPath expressions using our XPath toolbar.
If you place the caret in the Author document, the XPath expression is interpreted relative to the node which contains the caret offset.
Regards,
Radu
This is how XPath expressions work, even when you interpret it relative to a node, if you use a // construct then the expression is interpreted as absolute.
For your case you should have simply used the expression para which would have returned all para's from that element.
You can test XPath expressions using our XPath toolbar.
If you place the caret in the Author document, the XPath expression is interpreted relative to the node which contains the caret offset.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 9449
- Joined: Fri Jul 09, 2004 5:18 pm
Re: AuthorDocumentController findNodesByXpath not returning expected values
Hi Neil,
The Javadoc says something like:
but XPath expressions starting with "//" are not relative.
The XPath specification:
http://www.w3.org/TR/xpath/
gives some examples like:
Regards,
Radu
The Javadoc says something like:
Code: Select all
contextNode The node in the context of which the relative XPath Expressions will computed.
The XPath specification:
http://www.w3.org/TR/xpath/
gives some examples like:
//para selects all the para descendants of the document root and thus selects all para elements in the same document as the context node
So in your case you could have also used .//para and obtain the correct result..//para selects the para element descendants of the context node
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service