-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b44
-
generic
-
generic
-
Verified
Name: eaR10174 Date: 02/10/2004
RI does not take into account the attribute 'xsi:type' when an identity-constraint
is checked during validation of a document. RI complains that the element does not
have a simple type as required by the identity-constraint in case when in the schema
the element type is anyType and in the validated document the element type is substituted
by the simple type via the 'xsi:type' attribute.
According to the XML Schema Part 1: Stuctures specification the type specified by the
attribute 'xsi:type' should be used during validation of the element information item.
The bug affects the following new JCK-15 beta2 tests adopted from W3C XSTC-20020116 testsuite:
api/xml_schema/msxsdtest/identityConstraint/idF012.html#idF012_i
api/xml_schema/msxsdtest/identityConstraint/idF013.html#idF013_i
api/xml_schema/msxsdtest/identityConstraint/idF014.html#idF014_i
The sample is provided below; it fails on JDK 1.5.0-beta-b37.
------------------------------------test.xsd------------------------------
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="test">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:anyType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:key name="key1">
<xsd:selector xpath="."/>
<xsd:field xpath="child"/>
</xsd:key>
</xsd:element>
</xsd:schema>
------------------------------------test.xml------------------------------
<?xml version="1.0"?>
<test:root xmlns:test="test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="test test.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<child xsi:type="xsd:string">123</child>
</test:root>
------------------------------------Test.java-----------------------------
import java.io.File;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
public class Test {
protected static class ErrorHandler extends DefaultHandler {
public int errorCounter = 0;
public void error(SAXParseException e) throws SAXException {
System.out.println(e);
errorCounter++;
}
public void fatalError(SAXParseException e) throws SAXException {
System.out.println(e);
errorCounter++;
}
}
protected static SAXParser createParser() throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
SAXParser parser = spf.newSAXParser();
parser.setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
return parser;
}
public static void main(String [] args) {
ErrorHandler errorHandler = new ErrorHandler();
try {
SAXParser parser = createParser();
parser.parse(new File(args[0]), errorHandler);
} catch (Exception e) {
exit(1, "Fatal Error: " + e);
}
if (errorHandler.errorCounter == 0) {
exit(0, "PASSED.");
} else {
exit(1, "FAILED.");
}
}
public static void exit(int errCode, String msg) {
System.out.println(msg);
System.exit(errCode);
}
}
--------------------------------------------------------------------------
% java -showversion Test test.xml
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b37)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b37, mixed mode)
org.xml.sax.SAXParseException: cvc-id.3: A field of identity constraint 'key1'
matched element 'root', but this element does not have a simple type.
FAILED.
--------------------------------------------------------------------------
======================================================================
RI does not take into account the attribute 'xsi:type' when an identity-constraint
is checked during validation of a document. RI complains that the element does not
have a simple type as required by the identity-constraint in case when in the schema
the element type is anyType and in the validated document the element type is substituted
by the simple type via the 'xsi:type' attribute.
According to the XML Schema Part 1: Stuctures specification the type specified by the
attribute 'xsi:type' should be used during validation of the element information item.
The bug affects the following new JCK-15 beta2 tests adopted from W3C XSTC-20020116 testsuite:
api/xml_schema/msxsdtest/identityConstraint/idF012.html#idF012_i
api/xml_schema/msxsdtest/identityConstraint/idF013.html#idF013_i
api/xml_schema/msxsdtest/identityConstraint/idF014.html#idF014_i
The sample is provided below; it fails on JDK 1.5.0-beta-b37.
------------------------------------test.xsd------------------------------
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="test">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:anyType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:key name="key1">
<xsd:selector xpath="."/>
<xsd:field xpath="child"/>
</xsd:key>
</xsd:element>
</xsd:schema>
------------------------------------test.xml------------------------------
<?xml version="1.0"?>
<test:root xmlns:test="test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="test test.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<child xsi:type="xsd:string">123</child>
</test:root>
------------------------------------Test.java-----------------------------
import java.io.File;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
public class Test {
protected static class ErrorHandler extends DefaultHandler {
public int errorCounter = 0;
public void error(SAXParseException e) throws SAXException {
System.out.println(e);
errorCounter++;
}
public void fatalError(SAXParseException e) throws SAXException {
System.out.println(e);
errorCounter++;
}
}
protected static SAXParser createParser() throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
SAXParser parser = spf.newSAXParser();
parser.setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
return parser;
}
public static void main(String [] args) {
ErrorHandler errorHandler = new ErrorHandler();
try {
SAXParser parser = createParser();
parser.parse(new File(args[0]), errorHandler);
} catch (Exception e) {
exit(1, "Fatal Error: " + e);
}
if (errorHandler.errorCounter == 0) {
exit(0, "PASSED.");
} else {
exit(1, "FAILED.");
}
}
public static void exit(int errCode, String msg) {
System.out.println(msg);
System.exit(errCode);
}
}
--------------------------------------------------------------------------
% java -showversion Test test.xml
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b37)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b37, mixed mode)
org.xml.sax.SAXParseException: cvc-id.3: A field of identity constraint 'key1'
matched element 'root', but this element does not have a simple type.
FAILED.
--------------------------------------------------------------------------
======================================================================