<DIV>Hi All,</DIV>
<DIV>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV>Thanks,</DIV>
<DIV>Celso Jr</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#ff0000 size=2>&nbsp;=======================================================</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>&nbsp;=======================================================</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>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</P>
<P>&lt;exam id="001"&gt;</P>
<P>&lt;!-- Exam properties --&gt;</P>
<P>&lt;type&gt;SimpleExam&lt;/type&gt;</P>
<P>&lt;name&gt;Arandu Test Exam&lt;/name&gt;</P>
<P>&lt;description&gt;</P>
<P>A simple test wich shows some of the</P>
<P>features from Arandu.</P>
<P>&lt;/description&gt;</P>
<P>&lt;!-- Exam questions--&gt;</P>
<P>&lt;questions&gt;</P>
<P>&lt;question id="1"/&gt;</P>
<P>&lt;question id="2"/&gt;</P>
<P>&lt;/questions&gt;</P>
<P>&lt;/exam&gt;</P>
<P>=======================================================</P>
<P>And the xsd is:</P><FONT size=2>
<P>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</P>
<P>&lt;!--</P>
<P>$Revision: 1.3 $ </P>
<P>$Author: bairos $ </P>
<P>$Date: 2004/02/06 00:58:44 $</P>
<P>--&gt;</P>
<P>&lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;</P>
<P>&lt;xsd:annotation&gt;</P>
<P>&lt;xsd:documentation xml:lang="en"&gt;</P>
<P>Definition for an Exam. </P>
<P>&lt;/xsd:documentation&gt;</P>
<P>&lt;/xsd:annotation&gt;</P>
<P></P>
<P>&lt;xsd:element name="exam" type="BaseExam"/&gt;</P>
<P>&lt;xsd:complexType name="BaseExam"&gt;</P>
<P>&lt;xsd:sequence&gt;</P>
<P>&lt;xsd:element name="type" type="ExamType"/&gt;</P>
<P>&lt;xsd:element name="name" type="xsd:string"/&gt;</P>
<P>&lt;xsd:element name="description" minOccurs="0"/&gt;</P>
<P>&lt;xsd:element name="questions" type="Questions"/&gt;</P>
<P>&lt;/xsd:sequence&gt;</P>
<P>&lt;xsd:attribute name="id" type="xsd:string" use="required"/&gt;</P>
<P>&lt;/xsd:complexType&gt;</P>
<P>&lt;xsd:simpleType name="ExamType"&gt;</P>
<P>&lt;xsd:restriction base="xsd:string"&gt;</P>
<P>&lt;xsd:enumeration value="SimpleExam"/&gt;</P>
<P>&lt;/xsd:restriction&gt;</P>
<P>&lt;/xsd:simpleType&gt;</P>
<P>&lt;xsd:complexType name="Questions"&gt;</P>
<P>&lt;xsd:sequence&gt;</P>
<P>&lt;xsd:element name="question" type="Question" minOccurs="1" maxOccurs="unbounded"/&gt;</P>
<P>&lt;/xsd:sequence&gt;</P>
<P>&lt;/xsd:complexType&gt; </P>
<P>&lt;xsd:complexType name="Question"&gt;</P>
<P>&lt;xsd:attribute name="id" type="xsd:string" use="required"/&gt;</P>
<P>&lt;/xsd:complexType&gt; </P>
<P>&lt;/xsd:schema&gt;</P></FONT></FONT></FONT></FONT></FONT></DIV>