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 Cirip Tomas <to...@theimo.com> on 2002/05/07 19:49:45 UTC
XML Schema - validation problem
Hi folks,
I have a problem with validation using XML schema. The error message I am
getting:
[Error] cvc-elt.1: Cannot find the declaration of element 'my:family'.
and I don't understand why?! XML Spy validates XML document just fine. Both
files - family.xsd and family.xml are in the same directory. Thank you
Tomas
Java code:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setAttribute("http://xml.org/sax/features/validation",
Boolean.TRUE);
dbf.setAttribute("http://apache.org/xml/features/validation/schema",
Boolean.TRUE);
dbf.setAttribute("http://apache.org/xml/features/validation/schema-full-chec
king", Boolean.TRUE);
dbf.setAttribute("http://xml.org/sax/features/namespaces",
Boolean.TRUE);
dbf.setAttribute("http://apache.org/xml/features/continue-after-fatal-error"
, Boolean.TRUE);
DocumentBuilder parser = dbf.newDocumentBuilder();
Document document = parser.parse("d:\\temp\\family.xml");
...
XML file:
<?xml version="1.0" encoding="UTF-8"?>
<my:family xmlns:my="http://www.my.com"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="http://www.my.com family.xsd">
<my:father>John Smith</my:father>
<my:mother>Jane Doe</my:mother>
</my:family>
Schema file(family.xsd):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.my.com"
xmlns="http://www.my.com" elementFormDefault="qualified">
<xs:element name="family">
<xs:annotation>
<xs:documentation>Comment describing your
root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="father"/>
<xs:element name="mother"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: XML Schema - validation problem
Posted by Elena Litani <el...@ca.ibm.com>.
Tomas hi,
Cirip Tomas wrote:
> [Error] cvc-elt.1: Cannot find the declaration of element 'my:family'.
> and I don't understand why?! XML Spy validates XML document just fine. Both
> files - family.xsd and family.xml are in the same directory. Thank you
Xerces support XML Schema Rec, however you are using the Candidate Rec
namespace for XML Schemas:
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
Per XML Schema Rec [1] the namespaces are:
"http://www.w3.org/2001/XMLSchema"
"http://www.w3.org/2001/XMLSchema-instance"
[1] http://www.w3.org/TR/xmlschema-1/#Instance_Document_Constructions
--
Elena Litani / IBM Toronto
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org