Xpath in Plugin
Oxygen general issues.
-
- Posts: 96
- Joined: Mon May 09, 2011 11:54 am
Xpath in Plugin
Hi,
are there xml/xpath functions in an (document) plugin? I only get text-based functions and need to work with results restricted to xpaths (e.g. fileref-Attributes only from graphics inside figures (figure/graphic/@fileref).
How can I solve this?
Thanks,
Patrick
are there xml/xpath functions in an (document) plugin? I only get text-based functions and need to work with results restricted to xpaths (e.g. fileref-Attributes only from graphics inside figures (figure/graphic/@fileref).
How can I solve this?
Thanks,
Patrick
-
- Posts: 9445
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Xpath in Plugin
Hi Patrick,
What plugin extension type are you exactly using?
Is it "ro.sync.exml.plugin.document.DocumentPluginExtension"?
This is quite an old plugin type, the Workspace Access plugin extension type should be more powerful and flexible.
But even with the DocumentPluginExtension you can do stuff like:
Regards,
Radu
What plugin extension type are you exactly using?
Is it "ro.sync.exml.plugin.document.DocumentPluginExtension"?
This is quite an old plugin type, the Workspace Access plugin extension type should be more powerful and flexible.
But even with the DocumentPluginExtension you can do stuff like:
Code: Select all
@Override
public DocumentPluginResult process(DocumentPluginContext context) {
WSEditor currentEditorAccess = context.getPluginWorkspace().getCurrentEditorAccess(StandalonePluginWorkspace.MAIN_EDITING_AREA);
WSEditorPage cp = currentEditorAccess.getCurrentPage();
if(cp instanceof WSXMLTextEditorPage) {
//XML edited in Text mode.
try {
WSXMLTextNodeRange[] ranges = ((WSXMLTextEditorPage)cp).findElementsByXPath("//@id");
} catch (XPathException e) {
e.printStackTrace();
}
}
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 9445
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Xpath in Plugin
Hi Patrick,
You would more or less do it like:
Regards,
Radu
You would more or less do it like:
Code: Select all
WSXMLTextEditorPage xmlTextPage = ...;
WSXMLTextNodeRange range = ...;
try {
int startOffset = xmlTextPage.getOffsetOfLineStart(range.getStartLine()) + range.getStartColumn();
int endOffset = xmlTextPage.getOffsetOfLineStart(range.getEndColumn()) + range.getEndColumn();
String rangeText = xmlTextPage.getDocument().getText(startOffset, endOffset - startOffset);
} catch (BadLocationException e) {
e.printStackTrace();
}
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 96
- Joined: Mon May 09, 2011 11:54 am
Re: Xpath in Plugin
Hi Radu,
thank you, it works now. But another problem: I have tried to add buttons (using the example Workspace Access Plugin) - but the buttons do not have the style like the rest of oxygen. How can I add buttons with the same style which is set in the oxygen preferences?
thank you, it works now. But another problem: I have tried to add buttons (using the example Workspace Access Plugin) - but the buttons do not have the style like the rest of oxygen. How can I add buttons with the same style which is set in the oxygen preferences?
-
- Posts: 9445
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Xpath in Plugin
Hi Patrick,
Instead of JButtons you should create ro.sync.exml.workspace.api.standalone.ui.ToolbarButton which should look the same as our other toolbar buttons.
In the same API package ro.sync.exml.workspace.api.standalone.ui you may find other useful components.
Regards,
Radu
Instead of JButtons you should create ro.sync.exml.workspace.api.standalone.ui.ToolbarButton which should look the same as our other toolbar buttons.
In the same API package ro.sync.exml.workspace.api.standalone.ui you may find other useful components.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 96
- Joined: Mon May 09, 2011 11:54 am
Re: Xpath in Plugin
Thank you! But to the other problem with xpath:
Is there another solution which really supports xpath without these ranges? My project got a little bit more complex and now I have to search for a specific element and get its attributes. If I get the whole node as a string, I only get these attribute values with a regex search and this sounds dirty...
Is there another solution which really supports xpath without these ranges? My project got a little bit more complex and now I have to search for a specific element and get its attributes. If I get the whole node as a string, I only get these attribute values with a regex search and this sounds dirty...
-
- Posts: 9445
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Xpath in Plugin
Hi Patrick,
The problem is that the Text editing mode does not have a rigid node structure underneath (like the Author editing mode) so we do not really expose much API to look into its structure. Our Outline view in the Text editing mode is based on a semi-structured hierarchical model which we keep synchronized with the text changes but unfortunately we do not yet have API to access that structure, maybe we'll provide this in a future version.
You can also use this API method:
which usually returns an array of DOM nodes (or atomic values, depending on the XPath expression). But this is done without offering you the localization possible with the other XPath-based method which can only localize elements (and not attribute names and values from an element).
Regards,
Radu
The problem is that the Text editing mode does not have a rigid node structure underneath (like the Author editing mode) so we do not really expose much API to look into its structure. Our Outline view in the Text editing mode is based on a semi-structured hierarchical model which we keep synchronized with the text changes but unfortunately we do not yet have API to access that structure, maybe we'll provide this in a future version.
You can also use this API method:
Code: Select all
ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextEditorPage.evaluateXPath(String)
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)
- ↳ 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