Page 1 of 1

Validate document

Posted: Mon Oct 31, 2022 10:27 am
by SmitaPatil
Hi Team,
Can you please tell me if there is any method using which we can validate the content at selected caret position in document.

Thanks & Regards,
Smita

Re: Validate document

Posted: Mon Oct 31, 2022 10:57 am
by cristi_talau
Hello,
In Web Author there is the notion of a "valid document". I am not sure if you want to validate smaller pieces of content inside the document (you mentioned the caret position), and how would you determine the validity of such a fragment - XML Schemas validate entire documents only.

If you want to validate the entire document, you can draw some inspiration from this plugin which blocks saving a document when it is invalid: https://github.com/oxygenxml/web-author ... if-invalid .
Best,
Cristian

Re: Validate document

Posted: Wed Nov 02, 2022 12:01 pm
by SmitaPatil
Hi Cristian,
Suppose user has removed the tag in that case, after this change if document is not valid I can see red lines in the document.
can you tell which api we can use to check whether current document is valid or not based on schema.

Thanks & Regards,
Smitz

Re: Validate document

Posted: Wed Nov 02, 2022 12:43 pm
by cristi_talau
Hello,

The Java API is the following: WebappDocumentValidator.getValidationTask() (details here: https://www.oxygenxml.com/InstData/Edit ... tionTask--). You can see here how it is used: https://github.com/oxygenxml/web-author ... ess.js#L26

Best,
Cristian

Re: Validate document

Posted: Wed Nov 02, 2022 1:11 pm
by SmitaPatil
Hi Cristian,
I wonder how we can access authorDocumentModel at javascript side or client side.
Can you please tell me how we can access authorDocumentModel at js side. I want to call this method using js.

Thanks & Regards,
Smita

Re: Validate document

Posted: Wed Nov 02, 2022 1:38 pm
by cristi_talau
Hello,
The sample plugin I mentioned in the previous posts uses JS code that is run on the server using the Rhino JS engine. This code cannot run on the browser as it uses objects that are implemented in Java.
To call this API from JS code in browser, you can invoke AuthorOperations implemented in Java as described here: https://www.oxygenxml.com/maven/com/oxy ... esult.html .

Best,
Cristian