insertXMLFragment w/ Processing Instructions
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 37
- Joined: Tue Nov 30, 2010 7:34 pm
insertXMLFragment w/ Processing Instructions
Hopefully someone can help me. I'm trying to add a processing instruction using an AuthorOperation around the current selection. My code looks like:
As you can see, I've tried adding the processing instructions with "insertXMLFragment" and with "surroundInFragment". Individually, the end processing instruction gets added, but not the beginning and an Author message is displayed:
Code: Select all
int selStart = authorAccess.getEditorAccess().getSelectionStart();
int selEnd = authorAccess.getEditorAccess().getSelectionEnd();
if ( selEnd != selStart )
{
System.out.println("Adding processing instruction.");
//String fragmentStart = "<?oxy_insert_start?>";
//authorAccess.getDocumentController().insertXMLFragment(fragmentStart, selStart);
//String fragmentEnd = "<?oxy_insert_end?>";
//authorAccess.getDocumentController().insertXMLFragment(fragmentEnd, selEnd);
String fragment = "<?oxy_insert_start?><?oxy_insert_end?>";
authorAccess.getDocumentController().surroundInFragment(fragment, selStart, selEnd );
}
The surroundInFragment code doesn't generate any errors, but no PI's are added.[Document]:Found insert processing instruction without an end.
[Document]:Ignoring end processing instruction for insert change tracking which does not have a start.
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: insertXMLFragment w/ Processing Instructions
Hi,
Change tracking processing instructions are special and they should never be added as plain XML content.
Could you tell me more precisely what you are trying to achieve.
If you want to make changes via the API and have them recorded although change tracking is disabled, you can use the APIs ro.sync.ecss.extensions.api.ChangeTrackingController.toggleTrackChanges() and ChangeTrackingController.isTrackingChanges().
For example looking at your code you can first save the selected content to an AuthorDocumentFragment AuthorDocumentController.createDocumentFragment(int, int), then turn off change tracking using the API and delete the selected content (AuthorDocumentController.delete(int, int)). Then enable change tracking using the API and insert the fragment back in the document (AuthorDocumentController.insertFragment(int, AuthorDocumentFragment)).
Regards,
Radu
Change tracking processing instructions are special and they should never be added as plain XML content.
Could you tell me more precisely what you are trying to achieve.
If you want to make changes via the API and have them recorded although change tracking is disabled, you can use the APIs ro.sync.ecss.extensions.api.ChangeTrackingController.toggleTrackChanges() and ChangeTrackingController.isTrackingChanges().
For example looking at your code you can first save the selected content to an AuthorDocumentFragment AuthorDocumentController.createDocumentFragment(int, int), then turn off change tracking using the API and delete the selected content (AuthorDocumentController.delete(int, int)). Then enable change tracking using the API and insert the fragment back in the document (AuthorDocumentController.insertFragment(int, AuthorDocumentFragment)).
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 37
- Joined: Tue Nov 30, 2010 7:34 pm
Re: insertXMLFragment w/ Processing Instructions
Actually, all I'm trying to do is add change-tracking processing instructions surrounding the current expression. It's admittedly a little goofy adding "insert" processing instructions around changes , but for our particular use case, we don't need to know exactly what was changed (ie. change tracking). Change tracking would work, except we've had trouble rendering change tracking information reliably. I apply change bars between start and end tags, and inevitably our writers end up with change bars that wrap hundreds of pages.
Ultimately we just need to know where the change starts and ends and we use a custom element to describe each change. I was hoping to simplify the process of adding this information with a simple button.
I was able to wrap text in custom processing instructions, so my issue is clearly surrounding the protected oxy processing instructions.
Ultimately we just need to know where the change starts and ends and we use a custom element to describe each change. I was hoping to simplify the process of adding this information with a simple button.
I was able to wrap text in custom processing instructions, so my issue is clearly surrounding the protected oxy processing instructions.
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: insertXMLFragment w/ Processing Instructions
Hi,
Doing this will not work:
because you are inserting the start and end processing instructions in two separate stages.
And this approach:
will not work because the "surroundInFragment" was thought to usually takes an XML element as a fragment, otherwise it interprets those as two consecutive processing instructions, not as one which should be placed at the start of the selection, and one at the end.
I would recommend you try this approach:
This will work only if the end user has disabled change tracking. If they have change tracking enabled you can use our APi to turn it off, use the API to insert the content and then turn it on again.
Regards,
Radu
Doing this will not work:
Code: Select all
//String fragmentStart = "<?oxy_insert_start?>";
//authorAccess.getDocumentController().insertXMLFragment(fragmentStart, selStart);
//String fragmentEnd = "<?oxy_insert_end?>";
//authorAccess.getDocumentController().insertXMLFragment(fragmentEnd, selEnd);
And this approach:
Code: Select all
String fragment = "<?oxy_insert_start?><?oxy_insert_end?>";
authorAccess.getDocumentController().surroundInFragment(fragment, selStart, selEnd );
I would recommend you try this approach:
Code: Select all
if(authorAccess.getEditorAccess().hasSelection()) {
int selStart = authorAccess.getEditorAccess().getSelectionStart();
int selEnd = authorAccess.getEditorAccess().getSelectionEnd();
AuthorDocumentFragment selectedContent = authorAccess.getDocumentController().createDocumentFragment(selStart, selEnd - 1);
String selContentAsXML = authorAccess.getDocumentController().serializeFragmentToXML(selectedContent);
//Delete selected content
authorAccess.getDocumentController().delete(selStart, selEnd - 1);
String toInsert = "<?oxy_insert_start?>" + selContentAsXML + "<?oxy_insert_end?>";
authorAccess.getDocumentController().insertXMLFragment(toInsert, authorAccess.getEditorAccess().getCaretOffset());
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
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