How to highlight a string in xml document?
Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
-
- Posts: 5
- Joined: Mon Jul 24, 2023 9:47 pm
How to highlight a string in xml document?
Hi,
I have an xml document displayed in the oxygen xml editor and know the referenceGuid of the string I need to highlight.
Basically the reverse of what's asked in this thread but high lighting all the words inside the tag when I have the referenceGuid:
common-problems-f34/topic24987.html
Thank you,
Karen
I have an xml document displayed in the oxygen xml editor and know the referenceGuid of the string I need to highlight.
Basically the reverse of what's asked in this thread but high lighting all the words inside the tag when I have the referenceGuid:
common-problems-f34/topic24987.html
Thank you,
Karen
-
- Posts: 517
- Joined: Thu Sep 04, 2014 4:22 pm
Re: How to highlight a string in xml document?
Post by cristi_talau »
Hello,
What I understand is that you have the value of the "referenceGuid" of an attribute and you want to select the text inside the element.
If you are writing code inside a framework or plugin you can use the JS API:
Cristian
What I understand is that you have the value of the "referenceGuid" of an attribute and you want to select the text inside the element.
If you are writing code inside a framework or plugin you can use the JS API:
- to locate the XML DOM element that has a specific referenceGuid by doing a traversal of the DOM tree: https://www.oxygenxml.com/maven/com/oxy ... nt__anchor
- to select some content: https://www.oxygenxml.com/maven/com/oxy ... nager.html .
Cristian
-
- Posts: 5
- Joined: Mon Jul 24, 2023 9:47 pm
Re: How to highlight a string in xml document?
Hi Christian,
I'm using the following code and getting the following error (I am getting elements back in the getElementsByTagName call):
Thank you,
Karen
I'm using the following code and getting the following error (I am getting elements back in the getElementsByTagName call):
Code: Select all
var editingSupport = editorGlobal.getEditingSupport();
var elements = editingSupport.getDocument().getElementsByTagName("reference");
var selectionManager = editorGlobal.getSelectionManager();
var selection = selectionManager.createAroundNode(elements.item(0));
editorGlobal.getEditingSupport().getPersistentHighlightsManager().addHightlight(null);
highlight_error_snip.JPG
Could you please help me find the correct syntax?Thank you,
Karen
You do not have the required permissions to view the files attached to this post.
-
- Posts: 515
- Joined: Wed May 20, 2009 2:40 pm
Re: How to highlight a string in xml document?
Hello,
Maybe there is no 'reference' element in the document. Use console.log to print the resulting elements, to see if this is the case.
Best Regards,
Mihaela
Maybe there is no 'reference' element in the document. Use console.log to print the resulting elements, to see if this is the case.
Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
http://www.oxygenxml.com
-
- Posts: 5
- Joined: Mon Jul 24, 2023 9:47 pm
Re: How to highlight a string in xml document?
I didn't include the console.log statements in the code snippet. This is the output for document and elements. It looks like it is returning the two reference elements I have.
image.png
You do not have the required permissions to view the files attached to this post.
-
- Site Admin
- Posts: 172
- Joined: Tue Mar 20, 2018 5:28 pm
Re: How to highlight a string in xml document?
Post by Bogdan Dumitru »
Hello,
From the "Uncaught TypeError: Cannot read properties of undefined (reading 'getType')" it seems that you call SelectionManager.createAroundNode() with an undefined object as parameter. Please double-check that.
Also notice that the objects printed in the console from the last screenshot are sync.api.dom.Element objects, not HTMLElement objects.
If you consider that's a bug in one of the JavaScript API methods from Oxygen XML Web Author please provide the following:
From the "Uncaught TypeError: Cannot read properties of undefined (reading 'getType')" it seems that you call SelectionManager.createAroundNode() with an undefined object as parameter. Please double-check that.
Also notice that the objects printed in the console from the last screenshot are sync.api.dom.Element objects, not HTMLElement objects.
If you consider that's a bug in one of the JavaScript API methods from Oxygen XML Web Author please provide the following:
- the exact method that doesn't respect its documentation or that has a bug
- a script that we can run to reproduce the problem
- the expected behavior
- the actual behavior
Bogdan Dumitru
http://www.oxygenxml.com
http://www.oxygenxml.com
-
- Posts: 5
- Joined: Mon Jul 24, 2023 9:47 pm
Re: How to highlight a string in xml document?
This is one of the reference elements in the xml.
<description><reference referenceGuid="ffa25acc-4af5-4e13-9230-8d2255932be3">Two</reference> </description>
And this is the code with the console logs.
Could you please confirm this is the correct syntax for adding highlights?
<description><reference referenceGuid="ffa25acc-4af5-4e13-9230-8d2255932be3">Two</reference> </description>
And this is the code with the console logs.
Code: Select all
editorGlobal = e.editor;
var editingSupport = editorGlobal.getEditingSupport();
console.log("document: ", editingSupport.getDocument());
var elements = editingSupport.getDocument().getElementsByTagName("reference");
console.log("elements: ", elements);
var selectionManager = editorGlobal.getSelectionManager();
var selection = selectionManager.createAroundNode(elements.item(0));
console.log("selection: ", selection);
editorGlobal.getEditingSupport().getPersistentHighlightsManager().addHightlight(null);
-
- Posts: 515
- Joined: Wed May 20, 2009 2:40 pm
Re: How to highlight a string in xml document?
Hello,
Here are the changes you must do in your code, to add highlights to the reference elements:
1. Set the selection created around the reference node: after obtaining the selection from the createAroundNode method, you must call the setSelection API.
2. There is a typo in your code (addHightlight must be changed to addHighlight).
Also, make sure you first check if the list of elements is not empty (so that the "Cannot read properties of undefined (reading 'getType')" error wont happen again).
Best Regards,
Mihaela
Here are the changes you must do in your code, to add highlights to the reference elements:
1. Set the selection created around the reference node: after obtaining the selection from the createAroundNode method, you must call the setSelection API.
2. There is a typo in your code (addHightlight must be changed to addHighlight).
Also, make sure you first check if the list of elements is not empty (so that the "Cannot read properties of undefined (reading 'getType')" error wont happen again).
Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
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