Inserting Processing instruction

Post here questions and problems related to oXygen frameworks/document types.
Johann
Posts: 95
Joined: Wed Jun 17, 2015 12:46 pm

Inserting Processing instruction

Post by Johann » Thu Jan 30, 2020 5:10 pm

Hello,

I am using the Oxygen 21.1.0.2 SDK and I would like to insert a processing instruction inside my AuthorDocument through an operation.

The final objective is to be able to insert this kind of fragment:

Code: Select all

<myElement>
   <description>myDescription</description>
      <?PITarget id="1" ?>
      <?PITarget id="2" ?>
</myElement>
If it's not possible to insert the whole fragment at once, I tried to insert only :

Code: Select all

      <?PITarget id="1" ?>
but it failed.

How to do that insertion ?

Thanks,

Johann

Radu
Posts: 6916
Joined: Fri Jul 09, 2004 5:18 pm

Re: Inserting Processing instruction

Post by Radu » Thu Jan 30, 2020 5:23 pm

Hi Johann,

Maybe you could give us more details, tell us what API you tried for insertion, maybe give a small sample java code and also tell us what error Oxygen reported upon insertion.
In general to insert an XML fragment you should use the API ro.sync.ecss.extensions.api.AuthorDocumentController.insertXMLFragment(String, int).

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Johann
Posts: 95
Joined: Wed Jun 17, 2015 12:46 pm

Re: Inserting Processing instruction

Post by Johann » Thu Jan 30, 2020 5:34 pm

Hello Radu,


It's exactly what I tested :

Code: Select all

String myFragment = "<myElement><description>myDescription</description><?PITarget id=\"1\" ?><?PITarget id=\"2\" ?></myElement>";
authorAccess.getDocumentController().insertXMLFragment(myFragment, authorAccess.getEditorAccess().getCaretOffset());
and it returned me :

Code: Select all

Could not insert document fragment. Cause: ro.sync.ecss.dom.db cannot be cast to ro.sync.ecss.extensions.api.node.AuthorElement
Same result for this test :

Code: Select all

String myFragment = "<?PITarget id=\"1\" ?>";

authorAccess.getDocumentController().insertXMLFragment(myFragment, authorAccess.getEditorAccess().getCaretOffset());
If I remove the PI, it obviously works.


Regards,

Johann

Radu
Posts: 6916
Joined: Fri Jul 09, 2004 5:18 pm

Re: Inserting Processing instruction

Post by Radu » Fri Jan 31, 2020 11:08 am

Hi Johann,

I cannot reproduce this problem on my side. Where is the caret placed when the code is invoked? Is it inside an element?
After the error is reported in the Oxygen results view, can you right click it, choose "Show message" and then in the dialog which shows up there should be a "More details..." link which when pressed should show you a Java exception stack trace. Can you paste that stack trace in a reply on this thread?
Are you using our AuthorDocumentFilter API? If so, please make sure the exception is not thrown in your own code.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Johann
Posts: 95
Joined: Wed Jun 17, 2015 12:46 pm

Re: Inserting Processing instruction

Post by Johann » Fri Jan 31, 2020 5:21 pm

Hello Radu,

You were right. A Class cast exception was not well catched on our side (in a CustomDocumentFilter)... We considered AuthorNodes only as AuthorElements... This is no longer the case with the processing instructions.

My bad !

Thanks for your help,

Johann

Post Reply