[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
Thu Feb 21 13:05:50 PST 2008
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!
******************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20080221/ab65b66d/attachment.htm
More information about the jdom-interest
mailing list