[jdom-interest] org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element

Jasmin_Mehta at nexweb.org Jasmin_Mehta at nexweb.org
Mon Feb 25 05:41:52 PST 2008


I commented this line in my code

 saxBuilder.setValidation(true);

But still getting the same err.






Tatu Saloranta <cowtowncoder at yahoo.com> 
Sent by: jdom-interest-bounces at jdom.org
02/21/2008 06:08 PM

To
"jdom-interest at jdom.org" <jdom-interest at jdom.org>
cc

Subject
Re: [jdom-interest] org.xml.sax.SAXParseException: cvc-elt.1: Cannot find 
the declaration of element






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
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20080225/0ebadede/attachment.htm


More information about the jdom-interest mailing list