Page 1 of 1

Validate XML and throw error progrmatically

Posted: Thu Dec 15, 2022 1:29 pm
by ganem2
Hi Team,
I have scenarios where i need to check for few validations based on the content of xml and throw dynamic error messages. I have done few basic validations using schematron file as per customization guide. But i could not find any JAV API or approach to achieve same programmatically in customization guide. Could you please share a guide/document which can help me?

Oxygen XML Web author Version: 25
For basic validation Schematron file is supplied with Framework.

Re: Validate XML and throw error progrmatically

Posted: Thu Dec 15, 2022 5:51 pm
by mihaela
Hello,

There is a possibility to add a ro.sync.exml.workspace.api.editor.validation.ValidationProblemsFilter that allows you to update the list of validation problems.

Here is a sample plugin that uses this API:
https://github.com/oxygenxml/web-author ... ems-filter

Is this API suitable for your use case?

Best Regards,
Mihaela

Re: Validate XML and throw error progrmatically

Posted: Fri Dec 16, 2022 12:23 pm
by ganem2
Hello,

I tried to use ValidationProblemsFilter as per your suggestion and i was able to validate and throw custom error message, but when I click on message it does not select the error xml node.
for Schematron validation scenarios on click of error message target element is selected and cursor focus is shifted to error element.
below is the code snippet i used for creating custom error message. could you please let me know what i am missing here?

Code: Select all

@Override
public void filterValidationProblems(ValidationProblems validationProblems) {
		AuthorNode node = getErrorXMLNode(); // method to get author node where error scenario exists.
		List<DocumentPositionedInfo> problems = validationProblems.getProblemsList();
		if(null == problems) { // If there are no errors in document getProblemsList returns null.
			problems = new ArrayList<>(); 
		}
		AuthorDocumentPositionedInfo positionInfo = new AuthorDocumentPositionedInfo(
			DocumentPositionedInfo.SEVERITY_WARN, "Custom error message", node);
		problems.add(positionInfo)
		validationProblems.setProblemsList(problems);
}

Re: Validate XML and throw error progrmatically

Posted: Fri Dec 16, 2022 4:08 pm
by mihaela
Hello,

I tested and in my case, the node is selected. Can you log the node that you obtain from the getErrorXMLNode() method to see if it returns the expected node? Maybe it returns null (in this case the validation error is listed but nothing happens when you click on it).

Best Regards,
Mihaela

Re: Validate XML and throw error progrmatically

Posted: Mon Dec 19, 2022 4:23 pm
by ganem2
Hello,

I reverified my logic and i amde sure that i am not getting any null objects in place of node. for testing urpose i simplified my logic for getErrorXMLNode() as below.

Code: Select all

	public AuhorNode getErrorXMLNode(WSAuthorEditorPage page) throws AuthorOperationException{
		//getting all 'paratext' xml nodes in current document.
		AuthorNode[] nodes = page.getDocumentController().findNodesByXPath("//paratext", true, true, true);
		if (nodes.length > 0) {
			log.info("returning first para " + nodes[0].getDisplayName());
			return nodes[0];
		} else {
			throw new AuthorOperationException("Operation Failed");
		}
	}
I have verified through logs that above method is returning proper node. but still on click of warning message 'Custom error message' cursor is not getting focused on the element in this case first paratext node in document.

Re: Validate XML and throw error progrmatically

Posted: Mon Dec 19, 2022 6:04 pm
by mihaela
Hi,

We need your help to reproduce this problem. Any details would be helpful for us.
Are there any other validation items in the Validation view? When you select other item the corresponding element is selected?
Where is the focus when you select your validation item?

Can you send us a sample XML file, a video, and maybe your plugin to reproduce the problem? You can send them to support@oxygenxml.com if you want.

Best Regards,
Mihaela

Re: Validate XML and throw error progrmatically

Posted: Mon Dec 19, 2022 7:12 pm
by ganem2
Hi,

Yes i have configured schematron file validation through framework. schematron file is shared along with framework i.e inside teh custom framework directory. In this scenario along with my custom error message there is 1 more message due to schematron validation.
on clik of error message generated by schematron file target element is selected and focus is set on editor. when i click on custo error message focus remain in validation message right panel and no element is selectd in editor.

I will check with my Info team on what can be shared outside organization. If sharing is not option i will try to set up dummy plugin with reproducible code and share it.

Re: Validate XML and throw error progrmatically

Posted: Tue Dec 20, 2022 9:22 am
by ganem2
Hi,
I have attached the plugin code with sample xml. please take a look into this. use "mvn clean package" command to build plugin. after build jar will be placed under 'target\dist\plugins' folder
Development.zip
(7.74 KiB) Downloaded 333 times

Re: Validate XML and throw error progrmatically

Posted: Tue Dec 20, 2022 3:21 pm
by mihaela
Hello,

Thank you for the plugin. We uploaded it on a fresh installation of Web Author version 25.0 and the custom validation item appears in the Validation view. When clicking on it, the first paratext element is selected:
selection.png
selection.png (52 KiB) Viewed 2275 times
Is there any other customization in your test environment that could affect the selection?

Best Regards,
Mihaela

Re: Validate XML and throw error progrmatically

Posted: Tue Dec 20, 2022 5:11 pm
by ganem2
Hello,

I tried again with fresh installation of web author to see if any other items are causing issue but still facing the same issue. on click of error message nothing happens.
image.png
image.png (34.46 KiB) Viewed 2269 times
My web author version: Running oXygen XML Web Author 25.0, build 2022100711/2022100714 Copyright (c) 2022 Syncro Soft SRL

Re: Validate XML and throw error progrmatically

Posted: Wed Dec 21, 2022 10:08 am
by mihaela
Hi,

Can you please tell us what browser are you using?

Best Regards,
Mihaela

Re: Validate XML and throw error progrmatically

Posted: Wed Dec 21, 2022 10:10 am
by ganem2
Google Chrome Version 108.0.5359.125 (Official Build) (64-bit)

Re: Validate XML and throw error progrmatically

Posted: Wed Dec 21, 2022 12:33 pm
by mihaela
Hi,

Thank you, we also tested using this version of Chrome.

Other things to try:
1. Can you please check the Elements tab from the browser developer tools when the div corresponding to the "Custom error message" is selected, to see what are the values of data-start-pos and data-end-pos attributes?
image.png
image.png (135.24 KiB) Viewed 2220 times
2. Also, please look in the Console tab from the browser developer tools to see if there is an error in it.

Best Regards,
Mihaela

Re: Validate XML and throw error progrmatically

Posted: Wed Dec 21, 2022 1:14 pm
by ganem2
Hi,
I did not see any errors on console. below is the response which i saw in network log. also error message div's dont have any start and end position like shown in your screenshot.
image.png
image.png (19.88 KiB) Viewed 2212 times

Code: Select all

{
    "errors": [{
        "errorMessage": "There is no schema or DTD associated with the document. You can create an association either with the Associate Schema action or configuring in the Options the Preferences/Document Type Association list, or by creating a Validation Scenario.",
        "severity": "error",
        "startPosition": "",
        "endPosition": "",
        "nodeIds": [],
        "docTypeName": null,
        "scenarioName": null,
        "quickFixes": [],
        "additionalInfo": null
    }, {
        "errorMessage": "Custom error message paratext",
        "severity": "error",
        "startPosition": "",
        "endPosition": "",
        "nodeIds": [],
        "docTypeName": null,
        "scenarioName": null,
        "quickFixes": [],
        "additionalInfo": null
    }],
    "complete": true
}

Re: Validate XML and throw error progrmatically

Posted: Thu Dec 22, 2022 4:19 pm
by mihaela
Hello,

Thank you for the details. It seems that the start and end positions (for selection) are not set from the server side. This happens for example when the system Id of the editor does not correspond with the system id determined from the AuthorDocumentPositionedInfo.

Can you please modify your plugin to use the AuthorDocumentPositionedInfo constructor that also receives the systemID parameter and check again to see if the selection works in this case? The systemID can be obtained using controller.getAuthorDocument().getSystemID().

Best Regards,
Mihaela

Re: Validate XML and throw error progrmatically

Posted: Fri Dec 23, 2022 2:06 pm
by ganem2
Hello,
Thank you for your reply, adding systemID to postionedInfo constructor solved the issue. :D .