[jdom-interest] org.xml.sax.SAXParseException: cvc-elt.1: Cannot
find the declaration of element
Tatu Saloranta
cowtowncoder at yahoo.com
Thu Feb 21 15:08:17 PST 2008
Do not call
saxBuilder.setValidation(true);
unless you want to enabled DTD-based validation (it
does neither enable or disable schema-based
validation), and for what you need document to have
DOCTYPE declaration.
Without that Xerces gives this somewhat cryptic error
messsage: basically saying it doesn't have DTD-based
definition for the root element it sees.
Hope this helps,
-+ Tatu +-
--- Jasmin_Mehta at nexweb.org wrote:
> Hi,
>
> I am using org.jdom.input.SAXBuilder to validate the
> xml againts the
> schema and I am getting this exception:
>
> org.xml.sax.SAXParseException: cvc-elt.1: Cannot
> find the declaration of
> element 'Transmission'.
> 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:453)
> at
> org.jdom.input.SAXBuilder.build(SAXBuilder.java:851)
> at
>
org.nexweb.otm.util.JDOMSchemaValidator.validateSchema(JDOMSchemaValidator.java:39)
> Where 'Transmission' is the root element of my xml.
>
> Here is my class
>
> public class JDOMSchemaValidator
> {
> public void validateSchema(String
> schemaFileName, File
> xmlDocumentFile)
> {
> try
> { //Create SAXBuilder object
> SAXBuilder saxBuilder =
> new
> SAXBuilder("org.apache.xerces.parsers.SAXParser",
> true);
>
> //Set SAXBuilder parser to be a
> validating parser
> saxBuilder.setValidation(true);
>
>
saxBuilder.setFeature("http://apache.org/xml/features/validation/schema",
>
>
> true);
>
>
>
saxBuilder.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
>
>
> true);
>
>
saxBuilder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
>
>
> schemaFileName);
>
> //Create a ErrorHandler and set
> ErrorHandler on parser.
> Validator handler = new Validator();
> saxBuilder.setErrorHandler(handler);
> //Parse XML Document
> saxBuilder.build(xmlDocumentFile);
> //Output Validation Errors
> if (handler.validationError == true)
> {
> System.out.println("XML Document has
> Error:" +
>
> handler.validationError + " " +
> handler.saxParseException.getMessage());
> handler.saxParseException.printStackTrace();
> }
> else
> {
> System.out.println("XML Document is
> valid");
> }
> }
> catch (JDOMException jde)
> {
> System.out.println("JDOMException");
> jde.printStackTrace();
> }
>
> catch (IOException ioe)
> {
> System.out.println("IOException");
> ioe.printStackTrace();
> }
> }
>
> public static void main(String[] argv) {
> String schemaFile =
>
"file://F:/JavaProjects/WorkspaceDev/OTM/xml/catalog.xsd";
> File XmlFile = "catalog.xml";
> JDOMValidator validator = new
> JDOMValidator();
> validator.validateSchema(schemaFile,
> XmlFile);
>
> }
> }
> catalog.xsd
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <xsd:schema
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> attributeFormDefault="unqualified">
>
>
> <xsd:element name = "Transmission">
> .........
>
> catalog.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Transmission
> xmlns:xsi="http://www.w3.org/2001/XMLSchema"
>
xsi:noNamespaceSchemaLocation="file://F:/JavaProjects/WorkspaceDev/OTM/xml/GLogXML.xsd">
> <TransmissionHeader>
> .........................
>
>
>
******************************************************************************
> ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION
> Our domain name is changing. Please take note of
> the sender's
> e-Mail address and make changes to your personal
> address list,
> if needed. Both domains will continue to work, only
> for a limited
> time.
>
******************************************************************************
> This email and any files transmitted with it are
> intended solely for
> the use of the individual or agency to whom they are
> addressed.
> If you have received this email in error please
> notify the Navy
> Exchange Service Command e-mail administrator. This
> footnote
> also confirms that this email message has been
> scanned for the
> presence of computer viruses.
>
> Thank You!
>
******************************************************************************
>
> > _______________________________________________
> To control your jdom-interest membership:
>
http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
More information about the jdom-interest
mailing list