<br><font size=2 face="sans-serif">I commented this line in my code</font>
<br>
<br><font size=2><tt> saxBuilder.setValidation(true);</tt></font>
<br>
<br><font size=2 face="sans-serif">But still getting the same err.</font>
<br>
<br>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Tatu Saloranta <cowtowncoder@yahoo.com></b>
</font>
<br><font size=1 face="sans-serif">Sent by: jdom-interest-bounces@jdom.org</font>
<p><font size=1 face="sans-serif">02/21/2008 06:08 PM</font>
<td width=59%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif">"jdom-interest@jdom.org" <jdom-interest@jdom.org></font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Re: [jdom-interest] org.xml.sax.SAXParseException:
cvc-elt.1: Cannot find the declaration
of element</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=2><tt>Do not call <br>
<br>
saxBuilder.setValidation(true);<br>
<br>
unless you want to enabled DTD-based validation (it<br>
does neither enable or disable schema-based<br>
validation), and for what you need document to have<br>
DOCTYPE declaration.<br>
Without that Xerces gives this somewhat cryptic error<br>
messsage: basically saying it doesn't have DTD-based<br>
definition for the root element it sees.<br>
<br>
Hope this helps,<br>
<br>
-+ Tatu +-<br>
<br>
--- Jasmin_Mehta@nexweb.org wrote:<br>
<br>
> Hi,<br>
> <br>
> I am using org.jdom.input.SAXBuilder to validate the<br>
> xml againts the <br>
> schema and I am getting this exception:<br>
> <br>
> org.xml.sax.SAXParseException: cvc-elt.1: Cannot<br>
> find the declaration of <br>
> element 'Transmission'.<br>
> at <br>
><br>
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown<br>
> <br>
> Source)<br>
> at<br>
><br>
org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown<br>
> <br>
> Source)<br>
> at<br>
><br>
org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown<br>
> <br>
> Source)<br>
> at<br>
><br>
org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown<br>
> <br>
> Source)<br>
> at <br>
><br>
org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown<br>
> <br>
> Source)<br>
> at <br>
><br>
org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown<br>
> Source)<br>
> at <br>
><br>
org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown<br>
> <br>
> Source)<br>
> at <br>
><br>
org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown<br>
> <br>
> Source)<br>
> at <br>
><br>
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown<br>
> <br>
> Source)<br>
> at <br>
><br>
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown<br>
> <br>
> Source)<br>
> at<br>
><br>
org.apache.xerces.parsers.XML11Configuration.parse(Unknown<br>
> <br>
> Source)<br>
> at<br>
><br>
org.apache.xerces.parsers.XML11Configuration.parse(Unknown<br>
> <br>
> Source)<br>
> at<br>
> org.apache.xerces.parsers.XMLParser.parse(Unknown<br>
> Source)<br>
> at<br>
><br>
org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown<br>
> <br>
> Source)<br>
> at<br>
> org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)<br>
> at<br>
> org.jdom.input.SAXBuilder.build(SAXBuilder.java:851)<br>
> at <br>
><br>
org.nexweb.otm.util.JDOMSchemaValidator.validateSchema(JDOMSchemaValidator.java:39)<br>
> Where 'Transmission' is the root element of my xml.<br>
> <br>
> Here is my class<br>
> <br>
> public class JDOMSchemaValidator<br>
> { <br>
> public void validateSchema(String<br>
> schemaFileName, File <br>
> xmlDocumentFile)<br>
> {<br>
> try<br>
> { //Create SAXBuilder object<br>
> SAXBuilder saxBuilder =
<br>
> new<br>
> SAXBuilder("org.apache.xerces.parsers.SAXParser", <br>
> true);<br>
> <br>
> //Set SAXBuilder parser
to be a<br>
> validating parser<br>
> saxBuilder.setValidation(true);<br>
> <br>
><br>
saxBuilder.setFeature("http://apache.org/xml/features/validation/schema",<br>
> <br>
> <br>
>
true);<br>
> <br>
> <br>
><br>
saxBuilder.setFeature("http://apache.org/xml/features/validation/schema-full-checking",<br>
> <br>
> <br>
>
true);<br>
> <br>
><br>
saxBuilder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",<br>
> <br>
> <br>
>
schemaFileName);<br>
> <br>
> //Create a ErrorHandler
and set<br>
> ErrorHandler on parser.<br>
> Validator handler = new
Validator();<br>
> saxBuilder.setErrorHandler(handler);<br>
> //Parse XML Document<br>
> saxBuilder.build(xmlDocumentFile);<br>
> //Output Validation Errors<br>
> if (handler.validationError
== true)<br>
> {<br>
> System.out.println("XML
Document has<br>
> Error:" + <br>
>
<br>
> handler.validationError + " " + <br>
> handler.saxParseException.getMessage());<br>
> handler.saxParseException.printStackTrace();<br>
> }<br>
> else<br>
> {<br>
> System.out.println("XML
Document is<br>
> valid");<br>
> }<br>
> }<br>
> catch (JDOMException jde)<br>
> {<br>
> System.out.println("JDOMException");<br>
> jde.printStackTrace();<br>
> }<br>
> <br>
> catch (IOException ioe)<br>
> {<br>
> System.out.println("IOException");<br>
> ioe.printStackTrace();<br>
> }<br>
> }<br>
> <br>
> public static void main(String[] argv) {<br>
> String schemaFile
= <br>
><br>
"file://F:/JavaProjects/WorkspaceDev/OTM/xml/catalog.xsd";<br>
> File XmlFile
= "catalog.xml";<br>
> JDOMValidator
validator = new<br>
> JDOMValidator();<br>
> validator.validateSchema(schemaFile,<br>
> XmlFile);<br>
> <br>
> }<br>
> }<br>
> catalog.xsd<br>
> <br>
> <?xml version="1.0" encoding="UTF-8" ?><br>
> <xsd:schema<br>
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"<br>
> attributeFormDefault="unqualified">
<br>
> <br>
> <br>
> <xsd:element name = "Transmission"><br>
> .........<br>
> <br>
> catalog.xml<br>
> <br>
> <?xml version="1.0" encoding="UTF-8"?><br>
> <Transmission<br>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema" <br>
><br>
xsi:noNamespaceSchemaLocation="file://F:/JavaProjects/WorkspaceDev/OTM/xml/GLogXML.xsd"><br>
> <TransmissionHeader><br>
> .........................<br>
> <br>
> <br>
><br>
******************************************************************************<br>
> ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION <br>
> Our domain name is changing. Please take note of<br>
> the sender's<br>
> e-Mail address and make changes to your personal<br>
> address list,<br>
> if needed. Both domains will continue to work, only<br>
> for a limited<br>
> time.<br>
><br>
******************************************************************************<br>
> This email and any files transmitted with it are<br>
> intended solely for <br>
> the use of the individual or agency to whom they are<br>
> addressed. <br>
> If you have received this email in error please<br>
> notify the Navy <br>
> Exchange Service Command e-mail administrator. This<br>
> footnote <br>
> also confirms that this email message has been<br>
> scanned for the<br>
> presence of computer viruses.<br>
> <br>
> Thank You! <br>
><br>
******************************************************************************<br>
> <br>
> > _______________________________________________<br>
> To control your jdom-interest membership:<br>
><br>
http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com<br>
<br>
<br>
<br>
____________________________________________________________________________________<br>
Never miss a thing. Make Yahoo your home page. <br>
http://www.yahoo.com/r/hs<br>
_______________________________________________<br>
To control your jdom-interest membership:<br>
http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com<br>
</tt></font>
<br>