I have a maxLength facet on a complexType with simpleContent that extends a base complexType. Schema validation performed by the included program with the included schemas & xml file results in the stack trace listed below. Note the message refers to the relevant anonymous type as [type 'null'] which is not helpful. In this case, a more helpful error message would refer to either the complexType name itself or its base type name. Should I open a JIRA for this issue?
STACK TRACE: org.xml.sax.SAXParseException: cvc-maxLength-valid: Value ' commentZZZZZZZZZZZZZZZZZZ ' with length = '30' is not facet-valid with respect to maxLength '20' for type 'null'. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.elementLocallyValidComplexType(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.elementLocallyValidType(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.processElementContent(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.handleEndElement(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.endElement(Unknown Source) at org.apache.xerces.jaxp.validation.DOMValidatorHelper.finishNode(Unknown Source) at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source) at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source) at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source) at javax.xml.validation.Validator.validate(Validator.java:82) at test.XercesTest.testValidateComplexTypeWithSimpleContent(XercesTest.java:58) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at junit.framework.TestCase.runTest(TestCase.java:164) at junit.framework.TestCase.runBare(TestCase.java:130) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:120) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) TEST PROGRAM: package test; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import junit.framework.TestCase; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class XercesTest extends TestCase { public void testValidateComplexTypeWithSimpleContent() throws IOException, ParserConfigurationException, SAXException { System.setProperty( "javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); System.setProperty( "javax.xml.parsers.SaxParserFactory", "org.apache.xerces.jaxp.SaxParserFactoryImpl"); System.setProperty( "javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema", "org.apache.xerces.jaxp.validation.XMLSchemaFactory"); DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); dFactory.setNamespaceAware(true); String[] xsdFileNames = new String[] {"substitutionWithExtensionValues.xsd", "substitutionWithExtensionValues2.xsd"}; List xsdSourceList = new ArrayList(xsdFileNames.length); DocumentBuilder dBuilder = dFactory.newDocumentBuilder(); for (int i = 0; i < xsdFileNames.length; i++) { String xsdFileName = xsdFileNames[i]; Document document = dBuilder.parse(getClass().getResourceAsStream(xsdFileName)); DOMSource domSource = new DOMSource(document); xsdSourceList.add(domSource); } Source[] xsdSources = (Source[]) xsdSourceList.toArray(new DOMSource[xsdSourceList.size()]); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(xsdSources); String xmlFileName = "substitutionWithExtensionValues2.xml"; Document document = dBuilder.parse(getClass().getResourceAsStream(xmlFileName)); DOMSource domSource = new DOMSource(document); Validator validator = schema.newValidator(); validator.validate(domSource); } } SUBSTITUTIONWITHEXTENSIONVALUES.XSD <xsd:schema targetNamespace="http://www.example.com/substitutionEV" xmlns="http://www.example.com/substitutionEV" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sev="http://www.example.com/substitutionEV" elementFormDefault="qualified"> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <xsd:element name="results" type="sev:ResultsType" /> <xsd:element name="result" type="sev:ResultType" /> <xsd:element name="myResult" type="sev:MyResultType" substitutionGroup="sev:result" /> <xsd:complexType name="ResultsType"> <xsd:sequence> <xsd:element name="id" type="sev:IdType" /> <xsd:element ref="sev:result" minOccurs="0" maxOccurs="unbounded" /> <xsd:element name="comment" type="sev:CommentType" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="ResultType"> <xsd:sequence> <xsd:element name="id" type="sev:IdType" /> <xsd:element name="name" type="xsd:string" /> <xsd:element name="value" type="sev:ValueType" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="MyResultType"> <xsd:complexContent> <xsd:extension base="sev:ResultType" /> </xsd:complexContent> </xsd:complexType> <xsd:simpleType name="IdType"> <xsd:restriction base="sev:AsciiStringType"> <xsd:maxLength value="32" /> <xsd:pattern value="[0-9a-fA-F]*" /> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="AsciiStringType"> <xsd:restriction base="xsd:string"> <xsd:pattern value="\p{IsBasicLatin}*" /> </xsd:restriction> </xsd:simpleType> <xsd:complexType name="ValueType"> <xsd:simpleContent> <xsd:extension base="sev:Integer32Bit" /> </xsd:simpleContent> </xsd:complexType> <xsd:simpleType name="Integer32Bit"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="0" /> <xsd:maxInclusive value="4290000000" /> </xsd:restriction> </xsd:simpleType> <xsd:complexType name="CommentType"> <xsd:simpleContent> <xsd:extension base="sev:AsciiStringType"> <xsd:attribute name="language" use="optional"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:enumeration value="English" /> <xsd:enumeration value="French" /> <xsd:enumeration value="Spanish" /> </xsd:restriction> </xsd:simpleType> </xsd:attribute> </xsd:extension> </xsd:simpleContent> </xsd:complexType> <xsd:complexType name="MyCommentType"> <xsd:simpleContent> <xsd:restriction base="sev:CommentType"> <xsd:minLength value="0" /> <xsd:maxLength value="40" /> </xsd:restriction> </xsd:simpleContent> </xsd:complexType> </xsd:schema> SUBSTITUTIONWITHEXTENSIONVALUES2.XSD <xsd:schema targetNamespace="http://www.example.com/substitutionEV2" xmlns="http://www.example.com/substitutionEV2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sev2="http://www.example.com/substitutionEV2" xmlns:sev="http://www.example.com/substitutionEV" elementFormDefault="qualified"> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> schemaLocation="substitutionWithExtensionValues.xsd" /> <xsd:element name="allResults" type="sev2:AllResultsType" /> <xsd:complexType name="AllResultsType"> <xsd:sequence> <xsd:element name="id" type="sev2:Id2Type" /> <xsd:element name="results" minOccurs="0" maxOccurs="unbounded" type="sev2:Results2Type" /> <xsd:element name="comment" type="sev2:Comment2Type" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="Results2Type"> <xsd:complexContent> <xsd:extension base="sev:ResultsType" /> </xsd:complexContent> </xsd:complexType> <xsd:simpleType name="Id2Type"> <xsd:restriction base="sev:IdType"> <xsd:maxLength value="10" /> </xsd:restriction> </xsd:simpleType> <xsd:complexType name="Comment2Type"> <xsd:simpleContent> <xsd:restriction base="sev:CommentType"> <xsd:minLength value="0" /> <xsd:maxLength value="20" /> </xsd:restriction> </xsd:simpleContent> </xsd:complexType> </xsd:schema> SUBSTITUTIONWITHEXTENSIONVALUES2.XML <?xml version="1.0" encoding="ASCII"?> <sev2:id>FFFFFFFFFF</sev2:id> <sev:id>00000000000000000000</sev:id> <sev:result> <sev:id>11111111111111111111</sev:id> <sev:name>name1</sev:name> <sev:value>1</sev:value> </sev:result> <sev:myResult> <sev:id>22222222222222222222</sev:id> <sev:name>myName2</sev:name> <sev:value>2</sev:value> </sev:myResult> <sev:comment>comment0</sev:comment> </sev2:results> <sev:id>AAAAAAAAAAAAAAAAAAAA</sev:id> <sev:myResult> <sev:id>BBBBBBBBBBBBBBBBBBBB</sev:id> <sev:name>myNameB</sev:name> <sev:value>11</sev:value> </sev:myResult> <sev:comment>commentA</sev:comment> </sev2:results> <sev2:comment language="English"> commentZZZZZZZZZZZZZZZZZZ </sev2:comment> </sev2:allResults> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]