Jump to content
katja.radelicki@colruyt.be

org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of ..

Recommended Posts

Hello,I try to validate a DOM Document using:

SchemaFactory factory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);Source schemaFile=new StreamSource("myschema.xsd");schema schema=factory.newSchema(schemaFile);Validator validator=schema.newValidator();validator.validate(new DOMSource(document));

I don't validate using the parse(File) method, because I already have a DOM Tree in memory.BUT now I receive the following error:

org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'catalogue'.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.jaxp.validation.DOMValidatorHelper.beginNode(Unknown Source)at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)at org.apache.xerces.jaxp.validation.XMLSchemaValidator.validate(Unknown Source)at javax.xml.validation.Validator.validate(Unknown Source)

catalogue is my rootElement.A part of the XML file:

<?xml version="1.0" encoding="UTF-8"?><catalogue><date_created><day>1</day><month>7</month><year>2008</year></date_created><date_modified><day>1</day><month>7</month><year>2008</year></date_modified>

And a part of the XSD schema:

<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">	<xsd:element name="catalogue">    <xsd:complexType>      <xsd:sequence>        <xsd:element ref="date_created"/>        <xsd:element ref="date_modified"/>        <xsd:element ref="comment"/>        <xsd:element ref="books"/>        <xsd:element ref="cds"/>      </xsd:sequence>    </xsd:complexType>  </xsd:element>

(I'm using jdk 1.4.)Does somebody know how to solve this?Thank you!Katja

Share this post


Link to post
Share on other sites

It is some bug and normally it it solved in jdk 1.5see http://mail-archives.apache.org/mod_mbox/x....jira@brutus%3e But I tried to use jdk 1.5 and I still receive this error.Is there somebody who knows what to do?Thanks in advance!

Hello,I try to validate a DOM Document using:
SchemaFactory factory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);Source schemaFile=new StreamSource("myschema.xsd");schema schema=factory.newSchema(schemaFile);Validator validator=schema.newValidator();validator.validate(new DOMSource(document));

I don't validate using the parse(File) method, because I already have a DOM Tree in memory.BUT now I receive the following error:

org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'catalogue'.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.jaxp.validation.DOMValidatorHelper.beginNode(Unknown Source)at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)at org.apache.xerces.jaxp.validation.XMLSchemaValidator.validate(Unknown Source)at javax.xml.validation.Validator.validate(Unknown Source)

catalogue is my rootElement.A part of the XML file:

<?xml version="1.0" encoding="UTF-8"?><catalogue><date_created><day>1</day><month>7</month><year>2008</year></date_created><date_modified><day>1</day><month>7</month><year>2008</year></date_modified>

And a part of the XSD schema:

<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">	<xsd:element name="catalogue">    <xsd:complexType>      <xsd:sequence>        <xsd:element ref="date_created"/>        <xsd:element ref="date_modified"/>        <xsd:element ref="comment"/>        <xsd:element ref="books"/>        <xsd:element ref="cds"/>      </xsd:sequence>    </xsd:complexType>  </xsd:element>

(I'm using jdk 1.4.)Does somebody know how to solve this?Thank you!Katja

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...