Manipulating XML in text mode
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 11
- Joined: Fri Oct 04, 2019 11:26 pm
Manipulating XML in text mode
Post by jakubsimek »
Hi,
I am trying to figure out how I could write a plugin action for the text mode which would manipulate some elements or attributes. As far as I can see, the sample plugins in the SDK only demonstrate string manipulation for the text mode (e.g. capitalizing).
The "TextDocumentController" which can be used on "WSXMLTextEditorPage" only has a method for inserting an XML fragment.
Suppose I would like to insert an attribute on a certain element which is already present in the document. Could i use the "evaluateXPath" method on "WSXMLTextEditorPage" to return the element I want to manipulate? The method returns an array of java.lang.Object. Does this mean that in case the items returned by "evaluateXPath" are XML element nodes, I could then manipulate them "in place" as instances of something like "org.w3c.dom.Element"?
Would something like this be the way to go or are there other ways in the API to manipulate XML nodes in text mode?
I am a bloody beginner in the Oxygen SDK, so sorry if I am asking something which is perhaps obvious.
Best wishes,
Jakub
I am trying to figure out how I could write a plugin action for the text mode which would manipulate some elements or attributes. As far as I can see, the sample plugins in the SDK only demonstrate string manipulation for the text mode (e.g. capitalizing).
The "TextDocumentController" which can be used on "WSXMLTextEditorPage" only has a method for inserting an XML fragment.
Suppose I would like to insert an attribute on a certain element which is already present in the document. Could i use the "evaluateXPath" method on "WSXMLTextEditorPage" to return the element I want to manipulate? The method returns an array of java.lang.Object. Does this mean that in case the items returned by "evaluateXPath" are XML element nodes, I could then manipulate them "in place" as instances of something like "org.w3c.dom.Element"?
Would something like this be the way to go or are there other ways in the API to manipulate XML nodes in text mode?
I am a bloody beginner in the Oxygen SDK, so sorry if I am asking something which is perhaps obvious.
Best wishes,
Jakub
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Manipulating XML in text mode
Hi Jakub,
This is a good question, our API on the Text editing mode side is more primitive than the API for the Author visual editing mode. Partly this is because in the Text mode you might not have wellformed XML, so we cannot create a nodes structure over it.
Basically the Text page is a Swing JTextArea, and you can gain access to its internal document ro.sync.exml.workspace.api.editor.page.text.WSTextEditorPage.getDocument() if you want to perform insertions and deletions other than what our API allows.
This API gives you ranges of elements ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextEditorPage.findElementsByXPath(String). Each range has start line/column and end line/column information. After this you can use our API ro.sync.exml.workspace.api.editor.page.text.WSTextEditorPage.getOffsetOfLineStart(int) to convert line/column information to an offset in the document and thus obtain the offset range beween which an element exists, in this way you can retrieve the entire element content in a string, maybe manipulate it and then insert it back in the document.
Regards,
Radu
This is a good question, our API on the Text editing mode side is more primitive than the API for the Author visual editing mode. Partly this is because in the Text mode you might not have wellformed XML, so we cannot create a nodes structure over it.
Basically the Text page is a Swing JTextArea, and you can gain access to its internal document ro.sync.exml.workspace.api.editor.page.text.WSTextEditorPage.getDocument() if you want to perform insertions and deletions other than what our API allows.
This API gives you ranges of elements ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextEditorPage.findElementsByXPath(String). Each range has start line/column and end line/column information. After this you can use our API ro.sync.exml.workspace.api.editor.page.text.WSTextEditorPage.getOffsetOfLineStart(int) to convert line/column information to an offset in the document and thus obtain the offset range beween which an element exists, in this way you can retrieve the entire element content in a string, maybe manipulate it and then insert it back in the document.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 11
- Joined: Fri Oct 04, 2019 11:26 pm
Re: Manipulating XML in text mode
Post by jakubsimek »
Hi Radu,
Thanks a lot for this explanation. May I ask back about the evaluateXPath() method on WSXMLTextEditorPage? What kind of objects are being returned by this method if I e.g. address element nodes by the XPath expression?
Best,
Jakub
Thanks a lot for this explanation. May I ask back about the evaluateXPath() method on WSXMLTextEditorPage? What kind of objects are being returned by this method if I e.g. address element nodes by the XPath expression?
Best,
Jakub
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Manipulating XML in text mode
Hi Jakub,
The "evaluateXPath" should return an array of DOM "org.w3c.dom.Node". You can use it more to interrogate if certain XML elements are found and what they contain. Making changes to the DOM nodes will not update the XML content.
Regards,
Radu
The "evaluateXPath" should return an array of DOM "org.w3c.dom.Node". You can use it more to interrogate if certain XML elements are found and what they contain. Making changes to the DOM nodes will not update the XML content.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 11
- Joined: Fri Oct 04, 2019 11:26 pm
Re: Manipulating XML in text mode
Post by jakubsimek »
OK, thank you very much for explaining this.
Best,
Jakub
Best,
Jakub
Return to “SDK-API, Frameworks - Document Types”
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