Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected behavior when validating a xs:Date field #109

Open
FrankDBelli opened this issue May 22, 2020 · 1 comment
Open

unexpected behavior when validating a xs:Date field #109

FrankDBelli opened this issue May 22, 2020 · 1 comment

Comments

@FrankDBelli
Copy link

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!

@cowtowncoder
Copy link
Member

Quick note: although validation is accessed via Stax2-api, implementation is provided by Woodtox.
So will transfer issue to woodstox repo.

@cowtowncoder cowtowncoder transferred this issue from FasterXML/stax2-api May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants