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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to