woodstox
woodstox copied to clipboard
unexpected behavior when validating a xs:Date field
Hello all,
I’m trying to validate an XML file against its XSD schema (W3C) and I get an unexpected behaviour.
The XSD declares a tag of type xs:date
as below defined:
<xs:simpleType name="ISODate">
<xs:restriction base="xs:date"/>
</xs:simpleType>
<xs:element name="MyDate" type="ISODate"/>
The XML file I’m trying to validate against contains such tag with a value that I believe should be reported as wrong by the validation process (with woodstox-6.0.3):
<MyDate>2000-00-00</MyDate>
Instead, the incorrect value is not detected. If validated with other applications such as XmlSpy or other java parsers, the error is reported correctly. I’m wondering if there’s a feature I’ve not set (something like lenient date) or it’s actually a bug.
Source code follows:
public void test() throws Exception {
File myFile = new File("myFile.xml");
File myXsd = new File("myXSD.xsd");
XMLInputFactory _xmlif = XMLInputFactory.newFactory();
XMLValidationSchemaFactory _xmlValidationSchemaFactory = XMLValidationSchemaFactory
.newInstance(XMLValidationSchema.SCHEMA_ID_W3C_SCHEMA);
try (FileInputStream fis = new FileInputStream(myFile);
BufferedInputStream bis = new BufferedInputStream(fis);) {
XMLStreamReader2 xmlStreamReader2 = (XMLStreamReader2) _xmlif.createXMLStreamReader(bis,
XmlConstants.UTF_8);
xmlStreamReader2.validateAgainst(_xmlValidationSchemaFactory.createSchema(myXsd));
while (xmlStreamReader2.hasNext()) {
xmlStreamReader2.next();
}
xmlStreamReader2.closeCompletely();
System.out.println("File valid");
} catch (XMLStreamException e) {
System.out.println("File NOT valid");
}
}
Thanks in advance for your help!
Quick note: although validation is accessed via Stax2-api, implementation is provided by Woodtox. So will transfer issue to woodstox repo.