Project

Profile

Help

Support #6611

open

XSD Validation Throws Exception when validation fails.

Added by Nejdet Cemal Celik 4 days ago. Updated 3 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2024-12-18
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
12
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Hi,

I am trying to perform a schema validation with xsd file. Everything works fine when file is validated successfully. But when schema can't be validated, it throws "SaxonApiException". Is there any way to let it not throw exception ? Or is this natural way to handle the validation errors ? Also, when i have to get multiple errors from validation, it's just giving only one validation error.

Error Message :

One validation error was reported: In content of element <documentInfo>: The content model does not allow element <gl-cor:uniqueID2> to appear immediately after element <entriesType>. The following elements would be valid here: gl-muc:defaultCurrency, gl-bus:targetApplication, gl-bus:sourceApplication, gl-bus:periodUnitDescription, gl-bus:periodUnit, gl-bus:periodCount, gl-cor:periodCoveredEnd, gl-cor:periodCoveredStart, gl-cor:entriesComment, gl-bus:creator, and 5 others (or nothing).

Also here is the validation code :

void SchemaValidation()
{
    var validateFilePath = $@"E:\aa\xsdtest\some.xml";
    var xsdFile = $@"E:\aa\xsdtest\xsd\edefter.xsd";
    var xsdFileUri = new Uri(xsdFile);
    var validateFileUri = new Uri(validateFilePath);
    var processor = new Processor();

    processor.SchemaManager.Compile(xsdFileUri);
    var destination = new XdmDestination();

    List<string> _errors = new List<string>();

    SchemaValidationErrorHandler schemaValidationErrorHandler = new SchemaValidationErrorHandler(); 

    var schemaValidator = processor.SchemaManager.NewSchemaValidator();
    schemaValidator.UseXsiSchemaLocation = true;
    schemaValidator.InvalidityListener = errors => schemaValidationErrorHandler.Test(errors);

    try
    {
        schemaValidator.Validate(validateFileUri);
    }
    catch (SaxonApiException ex)
    {

    } 
}

I can provide xml and xsd if it's needed.


Files

clipboard-202412181629-zbfgk.png (111 KB) clipboard-202412181629-zbfgk.png Nejdet Cemal Celik, 2024-12-18 14:29

Please register to edit this issue

Also available in: Atom PDF