You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Pierpaolo Vittorini <pi...@cc.univaq.it> on 2007/02/15 18:33:50 UTC

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

As a couple of dozen of million users, I need to validate an xml document 
against an xml schema.

The (relevant portion of the) XML schema follows:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.med.univaq.it/vittorini/xdtfnse"
            xmlns="http://www.med.univaq.it/vittorini/xdtfnse">

  <xsd:element name="xdtfnse">
    <xsd:complexType>
      <xsd:sequence>
          ...SEVERAL ELEMENTS HERE...
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

</xsd:schema>

The (relevant portion of the) XML document follows:

<?xml version="1.0"?>
<xdtfnse xmlns="http://www.med.univaq.it/vittorini/xdtfnse"
         targetNamespace="http://www.med.univaq.it/vittorini/xdtfnse"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation=
                        "http://www.med.univaq.it/vittorini/xdtfnse
                        xdtfnse.xsd">
	...  CONTENT ...
</xdtfnse>

Therefore, I wrote a validator in Java (Xerces is xercesImpl-2.8.1.jar):

try {
      SchemaFactory factory = 
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      Schema schema = factory.newSchema(new File("xdtfnse.xsd"));
      Validator validator = schema.newValidator();
      DocumentBuilder parser = 
DocumentBuilderFactory.newInstance().newDocumentBuilder();
      Document document = parser.parse(new File("doc.xml"));
      validator.validate(new DOMSource(document));
} catch (Exception e) {
      e.printStackTrace();
}

Unfortunately, when I try to validate the above XML document against the 
Schema, I get the following error:

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

Question is: wrong namespace? namespace not correctly specified?

After several long searches in the web, I could not find any solution.
Please help me or please let me know where to find an answer.

Kind regards and please apologize if this question already appeared in the 
mailing list, but -- again -- all I found/read about this problem didn't 
suffice.

Pierpaolo Vittorini.

-- 
Pierpaolo Vittorini, PhD
Assistant Professor
INF/01 - Computer science
Department of Internal Medicine and Public Health
Via S. Salvatore - Edificio Delta 6 - 67010 L'Aquila fraz. Coppito
ITALY

E-mail address: pierpaolo.vittorini@cc.univaq.it
Personal web page: http://www.med.univaq.it/vittorini
Phone: +39 0862 434650
Fax: +39 0862 434656

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'xdtfnse'

Posted by Tim Carpenter <ti...@yahoo.co.uk>.
Pierpaolo,

Are you on Java 1.4.2 or V1.5?

I had a similar error when running on 1.4.2 if I did not endorse the  
Xerces and JAXP libraries.

brgds
Tim

On 15 Feb 2007, at 17:33, Pierpaolo Vittorini wrote:

> As a couple of dozen of million users, I need to validate an xml  
> document
> against an xml schema.
>
> The (relevant portion of the) XML schema follows:
>
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>             targetNamespace="http://www.med.univaq.it/vittorini/ 
> xdtfnse"
>             xmlns="http://www.med.univaq.it/vittorini/xdtfnse">
>
>   <xsd:element name="xdtfnse">
>     <xsd:complexType>
>       <xsd:sequence>
>           ...SEVERAL ELEMENTS HERE...
>       </xsd:sequence>
>     </xsd:complexType>
>   </xsd:element>
>
> </xsd:schema>
>
> The (relevant portion of the) XML document follows:
>
> <?xml version="1.0"?>
> <xdtfnse xmlns="http://www.med.univaq.it/vittorini/xdtfnse"
>          targetNamespace="http://www.med.univaq.it/vittorini/xdtfnse"
>          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>          xsi:schemaLocation=
>                         "http://www.med.univaq.it/vittorini/xdtfnse
>                         xdtfnse.xsd">
> 	...  CONTENT ...
> </xdtfnse>
>
> Therefore, I wrote a validator in Java (Xerces is  
> xercesImpl-2.8.1.jar):
>
> try {
>       SchemaFactory factory =
> SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
>       Schema schema = factory.newSchema(new File("xdtfnse.xsd"));
>       Validator validator = schema.newValidator();
>       DocumentBuilder parser =
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
>       Document document = parser.parse(new File("doc.xml"));
>       validator.validate(new DOMSource(document));
> } catch (Exception e) {
>       e.printStackTrace();
> }
>
> Unfortunately, when I try to validate the above XML document  
> against the
> Schema, I get the following error:
>
> org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the  
> declaration of
> element 'xdtfnse'.
>
> Question is: wrong namespace? namespace not correctly specified?
>
> After several long searches in the web, I could not find any solution.
> Please help me or please let me know where to find an answer.
>
> Kind regards and please apologize if this question already appeared  
> in the
> mailing list, but -- again -- all I found/read about this problem  
> didn't
> suffice.
>
> Pierpaolo Vittorini.
>
> -- 
> Pierpaolo Vittorini, PhD
> Assistant Professor
> INF/01 - Computer science
> Department of Internal Medicine and Public Health
> Via S. Salvatore - Edificio Delta 6 - 67010 L'Aquila fraz. Coppito
> ITALY
>
> E-mail address: pierpaolo.vittorini@cc.univaq.it
> Personal web page: http://www.med.univaq.it/vittorini
> Phone: +39 0862 434650
> Fax: +39 0862 434656
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>


		
___________________________________________________________ 
The all-new Yahoo! Mail goes wherever you go - free your email address from your Internet provider. http://uk.docs.yahoo.com/nowyoucan.html

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'xdtfnse'

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Pierpaolo,

You need to set namespace awareness to true on the DocumentBuilderFactory. 
XML schema validation requires namespace support.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Pierpaolo Vittorini <pi...@cc.univaq.it> wrote on 02/15/2007 
12:33:50 PM:

> As a couple of dozen of million users, I need to validate an xml 
document 
> against an xml schema.
> 
> The (relevant portion of the) XML schema follows:
> 
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>             targetNamespace="http://www.med.univaq.it/vittorini/xdtfnse"
>             xmlns="http://www.med.univaq.it/vittorini/xdtfnse">
> 
>   <xsd:element name="xdtfnse">
>     <xsd:complexType>
>       <xsd:sequence>
>           ...SEVERAL ELEMENTS HERE...
>       </xsd:sequence>
>     </xsd:complexType>
>   </xsd:element>
> 
> </xsd:schema>
> 
> The (relevant portion of the) XML document follows:
> 
> <?xml version="1.0"?>
> <xdtfnse xmlns="http://www.med.univaq.it/vittorini/xdtfnse"
>          targetNamespace="http://www.med.univaq.it/vittorini/xdtfnse"
>          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>          xsi:schemaLocation=
>                         "http://www.med.univaq.it/vittorini/xdtfnse
>                         xdtfnse.xsd">
>    ...  CONTENT ...
> </xdtfnse>
> 
> Therefore, I wrote a validator in Java (Xerces is xercesImpl-2.8.1.jar):
> 
> try {
>       SchemaFactory factory = 
> SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
>       Schema schema = factory.newSchema(new File("xdtfnse.xsd"));
>       Validator validator = schema.newValidator();
>       DocumentBuilder parser = 
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
>       Document document = parser.parse(new File("doc.xml"));
>       validator.validate(new DOMSource(document));
> } catch (Exception e) {
>       e.printStackTrace();
> }
> 
> Unfortunately, when I try to validate the above XML document against the 

> Schema, I get the following error:
> 
> org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of 

> element 'xdtfnse'.
> 
> Question is: wrong namespace? namespace not correctly specified?
> 
> After several long searches in the web, I could not find any solution.
> Please help me or please let me know where to find an answer.
> 
> Kind regards and please apologize if this question already appeared in 
the 
> mailing list, but -- again -- all I found/read about this problem didn't 

> suffice.
> 
> Pierpaolo Vittorini.
> 
> -- 
> Pierpaolo Vittorini, PhD
> Assistant Professor
> INF/01 - Computer science
> Department of Internal Medicine and Public Health
> Via S. Salvatore - Edificio Delta 6 - 67010 L'Aquila fraz. Coppito
> ITALY
> 
> E-mail address: pierpaolo.vittorini@cc.univaq.it
> Personal web page: http://www.med.univaq.it/vittorini
> Phone: +39 0862 434650
> Fax: +39 0862 434656
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org