Is there an XML schema validation library that supports the default attribute value?

If I read the XML Schema specification for the attribute values โ€‹โ€‹by default correctly, the validation process should actually modify the DOM to populate the default values.

default indicates that the attribute should appear unconditionally in * post-schema-validation infoset

Is this the correct reading of the specification? More importantly, do any libraries support (Java, C #, Python, etc.)?

In everything I've seen, the validate (document) method does not modify the document.

+2
source share
2 answers

Yes, this is the correct reading of the specification. But many XSD schema validators provide only a yes / no answer; they actually do not create a PSVI.

The Xerces validator certainly gives you access to the full PSVI, although I am not familiar with the API you need to use to view it.

The Saxon schema validator gives you access to the part of the PSVI that XSLT and XQuery use for the schema-oriented and includes extension attributes by default.

+2
source

Xerces2 (Java) provides default values, however this function must be enabled in the analyzer.

DOMParser parser=new DOMParser(); parser.setFeature("http://apache.org/xml/features/validation/schema", true); parser.setFeature("http://apache.org/xml/features/validation/schema/element-default", true); 

The circuit check function must be enabled.

See: Features of Xerces

0
source

Source: https://habr.com/ru/post/1337081/


All Articles