modifying text content via API
Oxygen general issues.
-
- Posts: 10
- Joined: Thu Nov 17, 2011 10:49 pm
modifying text content via API
Post by TimWallace »
I have a client who wants custom operations to edit certain content types (I have actions that build windows to maintain certain types of data that is part of the document). I have run into a problem being able to replace the text content of various AuthorNodes. I have no problem setting attributes, but I cannot figure out a way to set the contents of the text content that is contained within an element. Can someone please point me in the right direction?
-
- Posts: 515
- Joined: Wed May 20, 2009 2:40 pm
Re: modifying text content via API
Hi Tim,
To change the content of the AuthorNodes you can use the AuthorDocumentController, which provides methods for modifying the Author document:
To replace the text content of a node you can first delete this content by using the following method:
and then you can insert the new text content:
The offsets parameters represent positions in the Author document.
The following image presents an Author document fragment. The red markers indicate special control characters which are used to point to the start and the end offsets of the fragment containing nodes.

To find the start and end offsets of a node, use the and
methods from the AuthorNode.
Another approach is to iterate through all the text content intervals and replace the ones that you want to modify. Here is an example:
Regards,
Mihaela
---
Mihaela Calotescu
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
To change the content of the AuthorNodes you can use the AuthorDocumentController, which provides methods for modifying the Author document:
Code: Select all
AuthorDocumentController controller = authorAccess.getDocumentController();
Code: Select all
controller.delete(startOffset, endOffset);
Code: Select all
controller.insertText(offset, text);
The following image presents an Author document fragment. The red markers indicate special control characters which are used to point to the start and the end offsets of the fragment containing nodes.

To find the start and end offsets of a node, use the
Code: Select all
int getStartOffset();
Code: Select all
int getEndOffset();
Another approach is to iterate through all the text content intervals and replace the ones that you want to modify. Here is an example:
Code: Select all
AuthorDocumentController documentController = authorAccess.getDocumentController();
TextContentIterator iterator = documentController.getTextContentIterator(startOffset, endOffset);
try {
documentController.beginCompoundEdit();
// Iterate through text content intervals
while (iterator.hasNext()) {
TextContext next = iterator.next();
//Check first if this text can be edited
if (next.getEditableState() == TextContext.EDITABLE
|| next.getEditableState() == TextContext.EDITABLE_IN_FILTERED_CONDITIONAL_PROFILING) {
CharSequence textSequence = next.getText();
if (textSequence != null) {
String text = textSequence.toString();
if (text.contains("toReplace")) {
// Replace the modified string
next.replaceText(text.replaceAll("toReplace", "newText"));
}
}
}
}
} finally {
documentController.endCompoundEdit();
}
Regards,
Mihaela
---
Mihaela Calotescu
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
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