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: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

Pierpaolo Vittorini <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> Personal web page: http://www.med.univaq.it/vittorini
> Phone: +39 0862 434650
> Fax: +39 0862 434656
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to