Page 1 of 1

Inserting Processing instruction

Posted: Thu Jan 30, 2020 5:10 pm
by Johann
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

Re: Inserting Processing instruction

Posted: Thu Jan 30, 2020 5:23 pm
by Radu
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

Re: Inserting Processing instruction

Posted: Thu Jan 30, 2020 5:34 pm
by Johann
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

Re: Inserting Processing instruction

Posted: Fri Jan 31, 2020 11:08 am
by Radu
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

Re: Inserting Processing instruction

Posted: Fri Jan 31, 2020 5:21 pm
by Johann
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