FasterXML / FasterXML/woodstox
W3C Schema Validation does not cater for xs:unique constraints
- Dominant language
- Java
- Stars
- 259
- Forks
- 90
- Avg merge
- 16h 52m
- Merged PRs (30d)
- 2
Description
Consider the following XSD (called idc2.xsd):
```
```
And the corresponding (invalid) XML (called idc2.xml):
```
1
1
2
```
The following pom.xml dependencies I used:
```
com.fasterxml.woodstox
woodstox-core
5.0.3
msv
msv
20050913
relaxngDatatype
relaxngDatatype
20020414
com.sun.msv.datatype.xsd
xsdlib
2013.2
```
And the following example program (TestXSD.java):
```
package jdi.test.xsdvalidation;
import java.io.InputStream;
import javax.xml.stream.XMLInputFactory;
import org.codehaus.stax2.XMLInputFactory2;
import org.codehaus.stax2.XMLStreamReader2;
import org.codehaus.stax2.validation.XMLValidationException;
import org.codehaus.stax2.validation.XMLValidationSchema;
import org.codehaus.stax2.validation.XMLValidationSchemaFactory;
public class TestXSD {
public static void main(final String[] args) throws Exception {
final String xmlFileName = "idc2.xml";
final String xsdFileName = "idc2.xsd";
//load Schema
final XMLValidationSchemaFactory xmlValidationSchemaFactory = XMLValidationSchemaFactory.newInstance(XMLValidationSchema.SCHEMA_ID_W3C_SCHEMA);
final InputStream schemaInputStream = TestXSD.class.getResourceAsStream(xsdFileName);
final XMLValidationSchema xmlValidationSchema = xmlValidationSchemaFactory.createSchema(schemaInputStream);
//load (invalid) XML file
final InputStream xmlInputStream = TestXSD.class.getResourceAsStream(xmlFileName);
final XMLInputFactory2 xmlInputFactory2 = (XMLInputFactory2)XMLInputFactory.newInstance();
final XMLStreamReader2 xmlStreamReader =(XMLStreamReader2) xmlInputFactory2.createXMLStreamReader(xmlInputStream);
try{
//validate the XML file
xmlStreamReader.validateAgainst(xmlValidationSchema);
//traverse the streaming document
while(xmlStreamReader.hasNext()){
xmlStreamReader.next();
}
} catch(final XMLValidationException e){
//catch validation exception
System.err.println("XML file: " + xmlFileName + " failed to validatate against: " + relaxNgFileName);
return ;
}
System.out.println("XML file: " + xmlFileName + " successfully validated against: " + relaxNgFileName);
}
}
```
produces the not expected output:
XML file: idc2.xml successfully validated against: idc2.xsd
Note:
- Xerces-J 2.11 and Eclipse validate this file correctly.
Apparently I suspect that the class GenericMsvValidator is not doing any of Unique, Key, KeyRef validations. Only ID and IDREF seems to be supported (not sure whether this coincides with Key / KeyRef respectively). I have not found out whether this is supposed to be the case or just an issue. I furthermore discovered the field mVGM.grammer.topLevel.element.identityConstraints did contain the unique constraint.
The obvious suggestion to use Xerces-J instead does not solve my problem either, as https://issues.apache.org/jira/browse/XERCESJ-1276 is doing unique constraint validation in O(n^2) instead of O(n log(n)) as expected.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.