You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by ds...@mmm.com on 2001/05/17 14:17:37 UTC

Can't Validate against a Schema...


I'm using the Xerces 1.3.1 release and I'm trying to get there exmple validating
an XML doc against a schema....The error I get is
Generated fault:SAXException
Error msg:Element type "personnel" must be declared.

My suspicion is that the schema is not being loaded...here is my code..I'm using
VAJava 3.5 on an NT4.0 machine...If I don't set the parsing the document loads
just fine...I can't be the only one who's had trouble with this...how is
everyone else validating their documents?

main method....

DOMParser myparser = new DOMParser();
     myparser.setFeature("http://xml.org/sax/features/validation", true);
     MyErrorHandler err = new MyErrorHandler();
     myparser.setErrorHandler(err);

     try {
     myparser.parse(new
InputSource("file:///D:/MES_WebSite/development/xmldoc/person-schema.xml"));

     }
     catch (org.xml.sax.SAXException ex) {
               System.err.println("Generated fault:SAXException ");
               System.err.println("Error msg:" + ex.getMessage());
               return;
          } catch (IOException ex) {
               System.err.println("Generated fault:IOException ");
               System.err.println("Error msg:" + ex.getMessage());
               return;
          } catch (Exception ex) {
               System.err.println("Generated fault:Exception ");
               System.err.println("Error msg:" + ex.getMessage());
               return;
          }

Here is the xml...
<?xml version="1.0" encoding="UTF-8"?>
 <personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema"
     xsi:noNamespaceSchemaLocation="
http://localhost/mesapi/schema/version1.0/personal.xsd">
 <person id="Big.Boss">
 <name>
  <family>Boss</family>
  <given>Big</given>
  </name>
  <email>chief@foo.com</email>
  <link subordinates="one.worker two.worker three.worker four.worker
five.worker" />
  </person>
 <person>
 <name>
  <family>Worker</family>
  <given>One</given>
  </name>
  <email>one@foo.com</email>
  <link manager="Big.Boss" />
  </person>
 <person id="two.worker">
 <name>
  <family>Worker</family>
  <given>Two</given>
  </name>
  <email>two@foo.com</email>
  <link manager="Big.Boss" />
  </person>
 <person id="three.worker">
 <name>
  <family>Worker</family>
  <given>Three</given>
  </name>
  <email>three@foo.com</email>
  <link manager="Big.Boss" />
  </person>
 <person id="four.worker">
 <name>
  <family>Worker</family>
  <given>Four</given>
  </name>
  <email>four@foo.com</email>
  <link manager="Big.Boss" />
  </person>
 <person id="five.worker">
 <name>
  <family>Worker</family>
  <given>Five</given>
  </name>
  <email>five@foo.com</email>
  <link manager="Big.Boss" />
  </person>
  </personnel>

And here is the XSD...
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
 <element name="personnel">
    <complexType>
       <sequence>
          <element ref="person" minOccurs="1" maxOccurs="unbounded" />
       </sequence>
    </complexType>
     <unique name="unique1">
       <selector xpath="person" />
          <field xpath="@name" />
     </unique>
    <key name="empid">
       <selector xpath="person" />
       <field xpath="@id" />
    </key>
    <keyref name="keyref1" refer="empid">
         <selector xpath="person" />
            <field xpath="link/@manager" />
     </keyref>
  </element>

 <element name="person">
    <complexType>
        <sequence>
       <element ref="name" />
       <element ref="email" minOccurs="0" maxOccurs="unbounded" />
       <element ref="url" minOccurs="0" maxOccurs="unbounded" />
       <element ref="link" minOccurs="0" maxOccurs="1" />
     </sequence>
     <attribute name="id" type="ID" use="required" />
     <attribute name="note" type="string" />
     <attribute name="contr" default="false">
      <simpleType>
        <restriction base="string">
          <enumeration value="true" />
          <enumeration value="false" />
        </restriction>
      </simpleType>
     </attribute>
     <attribute name="salary" type="integer" />
    </complexType>
  </element>

 <element name="name">
    <complexType>
     <all>
        <element ref="family" />
        <element ref="given" />
     </all>
    </complexType>
 </element>

 <element name="family" type="string" />
 <element name="given" type="string" />
 <element name="email" type="string" />
 <element name="url">
    <complexType>
     <attribute name="href" type="string" default="http://" />
    </complexType>
 </element>

  <element name="link">
     <complexType>
     <attribute name="manager" type="IDREF" />
     <attribute name="subordinates" type="IDREFS" />
     </complexType>
  </element>
  <notation name="gif" public="//APP/Photoshop/4.0" system="photoshop.exe" />
</schema>