<DIV>Hi All,</DIV>
<DIV> </DIV>
<DIV>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.</DIV>
<DIV>I would be grateful if anybody can help me.</DIV>
<DIV> </DIV>
<DIV>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.</DIV>
<DIV> </DIV>
<DIV>Thanks,</DIV>
<DIV>Celso Jr</DIV>
<DIV> </DIV>
<DIV><FONT color=#ff0000 size=2> =======================================================</FONT></DIV>
<DIV><FONT color=#ff0000 size=2><FONT color=#ff0000 size=2>
<P>org.tupi.arandu.core.persistence.ExamReaderException: org.jdom.input.JDOMParseException: Error on line 7: cvc-elt.1: Cannot find the declaration of element 'exam'.</P>
<P>at org.tupi.arandu.core.persistence.xml.XMLAbstractExamReader.getExamType(XMLAbstractExamReader.java:164)</P>
<P>at org.tupi.arandu.core.persistence.xml.XMLAbstractExamReader.main(XMLAbstractExamReader.java:187)</P>
<P>Caused by: org.jdom.input.JDOMParseException: Error on line 7: cvc-elt.1: Cannot find the declaration of element 'exam'.</P>
<P>at org.jdom.input.SAXBuilder.build(SAXBuilder.java:381)</P>
<P>at org.jdom.input.SAXBuilder.build(SAXBuilder.java:684)</P>
<P>at org.tupi.arandu.core.persistence.xml.XMLAbstractExamReader.readDocument(XMLAbstractExamReader.java:122)</P>
<P>at org.tupi.arandu.core.persistence.xml.XMLAbstractExamReader.getExamType(XMLAbstractExamReader.java:162)</P>
<P>... 1 more</P>
<P>Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'exam'.</P>
<P>at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)</P>
<P>at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)</P>
<P>at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)</P>
<P>at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)</P>
<P>at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)</P>
<P>at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)</P>
<P>at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)</P>
<P>at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)</P>
<P>at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)</P>
<P>at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)</P>
<P>at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)</P>
<P>at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)</P>
<P>at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)</P>
<P>at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)</P>
<P>at org.jdom.input.SAXBuilder.build(SAXBuilder.java:370)</P>
<P>... 4 more</P>
<P>Exception in thread "main" </P></FONT></DIV>
<DIV>
<P> =======================================================</P>
<P><FONT style="BACKGROUND-COLOR: #ffffff" color=#000000>=======================================================</FONT></P>
<P><FONT style="BACKGROUND-COLOR: #ffffff" color=#000000>The code I use to validate create a document validating the schema is:</FONT></P><FONT color=#000000><FONT size=2><B><FONT color=#7f0055 size=2>
<P></B></FONT><B><FONT color=#7f0055 size=2>final</B></FONT><FONT size=2> String SCHEMA_LOCATION = </FONT><FONT color=#2a00ff size=2>"C:\\projects\\Arandu\\core\\res\\exam.xsd"</FONT><FONT size=2>;</P></FONT>
<P>Document xmlDocument;</P>
<P></P>
<P>SAXBuilder builder = </FONT><B><FONT color=#7f0055 size=2>new</B></FONT><FONT size=2> SAXBuilder(</FONT><FONT color=#2a00ff size=2>"org.apache.xerces.parsers.SAXParser"</FONT><FONT size=2>);</P>
<P>builder.setValidation(</FONT><B><FONT color=#7f0055 size=2>true</B></FONT><FONT size=2>); </P>
<P>builder.setFeature(</FONT><FONT color=#2a00ff size=2>"http://apache.org/xml/features/validation/schema"</FONT><FONT size=2>, </FONT><B><FONT color=#7f0055 size=2>true</B></FONT><FONT size=2>);</P>
<P>builder.setProperty(</FONT><FONT color=#2a00ff size=2>"http://apache.org/xml/properties/schema/external-schemaLocation"</FONT><FONT size=2>, SCHEMA_LOCATION);</P><FONT size=2>
<P></FONT><FONT color=#3f7f5f size=2>//exception is throw next line given that in is an InputStream to the XML previously declared</P></FONT>
<P>xmlDocument = builder.build(in);</P>
<P></P>
<P></FONT><B><FONT color=#7f0055 size=2>return</B></FONT><FONT size=2> xmlDocument;</FONT></P>
<P><FONT size=2>=======================================================</FONT></P>
<P><FONT size=2>The XML file is:</FONT></P><FONT size=2><FONT size=2>
<P><?xml version="1.0" encoding="UTF-8"?></P>
<P><exam id="001"></P>
<P><!-- Exam properties --></P>
<P><type>SimpleExam</type></P>
<P><name>Arandu Test Exam</name></P>
<P><description></P>
<P>A simple test wich shows some of the</P>
<P>features from Arandu.</P>
<P></description></P>
<P><!-- Exam questions--></P>
<P><questions></P>
<P><question id="1"/></P>
<P><question id="2"/></P>
<P></questions></P>
<P></exam></P>
<P>=======================================================</P>
<P>And the xsd is:</P><FONT size=2>
<P><?xml version="1.0" encoding="UTF-8"?></P>
<P><!--</P>
<P>$Revision: 1.3 $ </P>
<P>$Author: bairos $ </P>
<P>$Date: 2004/02/06 00:58:44 $</P>
<P>--></P>
<P><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"></P>
<P><xsd:annotation></P>
<P><xsd:documentation xml:lang="en"></P>
<P>Definition for an Exam. </P>
<P></xsd:documentation></P>
<P></xsd:annotation></P>
<P></P>
<P><xsd:element name="exam" type="BaseExam"/></P>
<P><xsd:complexType name="BaseExam"></P>
<P><xsd:sequence></P>
<P><xsd:element name="type" type="ExamType"/></P>
<P><xsd:element name="name" type="xsd:string"/></P>
<P><xsd:element name="description" minOccurs="0"/></P>
<P><xsd:element name="questions" type="Questions"/></P>
<P></xsd:sequence></P>
<P><xsd:attribute name="id" type="xsd:string" use="required"/></P>
<P></xsd:complexType></P>
<P><xsd:simpleType name="ExamType"></P>
<P><xsd:restriction base="xsd:string"></P>
<P><xsd:enumeration value="SimpleExam"/></P>
<P></xsd:restriction></P>
<P></xsd:simpleType></P>
<P><xsd:complexType name="Questions"></P>
<P><xsd:sequence></P>
<P><xsd:element name="question" type="Question" minOccurs="1" maxOccurs="unbounded"/></P>
<P></xsd:sequence></P>
<P></xsd:complexType> </P>
<P><xsd:complexType name="Question"></P>
<P><xsd:attribute name="id" type="xsd:string" use="required"/></P>
<P></xsd:complexType> </P>
<P></xsd:schema></P></FONT></FONT></FONT></FONT></FONT></DIV>