[jdom-interest] Schema Validation
celsogbj
celsogbj at terra.com.br
Wed Feb 11 09:48:10 PST 2004
Hi All,
I am having a problem with schema valitadion and JDom. I've read many messages in this forum and read the faq of JDom and I still didn't get the answer.
I would be grateful if anybody can help me.
Here are the stack trace of the exception I get at runtime, the code fragment that create the Document and generate this exception and my xml file and my xsd file.
Thanks,
Celso Jr
=======================================================
org.tupi.arandu.core.persistence.ExamReaderException: org.jdom.input.JDOMParseException: Error on line 7: cvc-elt.1: Cannot find the declaration of element 'exam'.
at org.tupi.arandu.core.persistence.xml.XMLAbstractExamReader.getExamType(XMLAbstractExamReader.java:164)
at org.tupi.arandu.core.persistence.xml.XMLAbstractExamReader.main(XMLAbstractExamReader.java:187)
Caused by: org.jdom.input.JDOMParseException: Error on line 7: cvc-elt.1: Cannot find the declaration of element 'exam'.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:381)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:684)
at org.tupi.arandu.core.persistence.xml.XMLAbstractExamReader.readDocument(XMLAbstractExamReader.java:122)
at org.tupi.arandu.core.persistence.xml.XMLAbstractExamReader.getExamType(XMLAbstractExamReader.java:162)
... 1 more
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'exam'.
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.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:370)
... 4 more
Exception in thread "main"
=======================================================
=======================================================
The code I use to validate create a document validating the schema is:
final String SCHEMA_LOCATION = "C:\\projects\\Arandu\\core\\res\\exam.xsd";
Document xmlDocument;
SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
builder.setValidation(true);
builder.setFeature("http://apache.org/xml/features/validation/schema", true);
builder.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", SCHEMA_LOCATION);
//exception is throw next line given that in is an InputStream to the XML previously declared
xmlDocument = builder.build(in);
return xmlDocument;
=======================================================
The XML file is:
<?xml version="1.0" encoding="UTF-8"?>
<exam id="001">
<!-- Exam properties -->
<type>SimpleExam</type>
<name>Arandu Test Exam</name>
<description>
A simple test wich shows some of the
features from Arandu.
</description>
<!-- Exam questions-->
<questions>
<question id="1"/>
<question id="2"/>
</questions>
</exam>
=======================================================
And the xsd is:
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Revision: 1.3 $
$Author: bairos $
$Date: 2004/02/06 00:58:44 $
-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation xml:lang="en">
Definition for an Exam.
</xsd:documentation>
</xsd:annotation>
<xsd:element name="exam" type="BaseExam"/>
<xsd:complexType name="BaseExam">
<xsd:sequence>
<xsd:element name="type" type="ExamType"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="description" minOccurs="0"/>
<xsd:element name="questions" type="Questions"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:simpleType name="ExamType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="SimpleExam"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="Questions">
<xsd:sequence>
<xsd:element name="question" type="Question" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Question">
<xsd:attribute name="id" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:schema>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20040211/e2793abf/attachment.htm
More information about the jdom-interest
mailing list