Schema validation ( and my pain in the u know what)

Discussion in 'XML' started by motoman, Oct 15, 2004.

  1. motoman

    motoman Guest

    i have the following code (see below), i run my validation and get
    unexpected results.

    Public ID: null
    System ID: file:///C:/DATA/Sandpit/Eclipse/workspace/dtdValidation/memory.xml
    Line number: 4
    Column number: 44
    Message: Element type "memories" must be declared.

    Public ID: null
    System ID: file:///C:/DATA/Sandpit/Eclipse/workspace/dtdValidation/memory.xml
    Line number: 5
    Column number: 24
    Message: Element type "memory" must be declared.

    and so on for almost every element in the XML where i should be
    getting real schema errors eg.

    Public ID: null
    System ID: file:///D:/herong/dictionary_invalid_xsd.xml
    Line number: 7
    Column number: 22
    Message: cvc-datatype-valid.1.2.1: 'yes' is not a valid 'boolean'
    value.
    ...............

    To me it looks like the validation is not actually picking up the
    schema, does this sound right?. The schema and xml are both in the
    same directory. Can someone give me some ideas on the possible source
    of the problem.
    I have been looking at previous posts on this forum and nobody seems
    to be getting an answer. Please help i am despirate here, my deadline
    date is approaching fast.


    class validation {

    public static StringBuffer sErrorBuffer = new StringBuffer();

    public static void main(String args[]) {
    try {

    String parserClass = "org.apache.xerces.parsers.SAXParser";
    String validationFeature
    = "http://xml.org/sax/features/validation";
    String schemaFeature
    = "http://apache.org/xml/features/validation/schema";

    XMLReader r = XMLReaderFactory.createXMLReader(parserClass);
    r.setFeature(validationFeature,true);
    r.setFeature(schemaFeature,true);
    r.setErrorHandler(new MyErrorHandler());
    r.parse("memory.xml");

    System.out.println(sErrorBuffer.toString());

    System.out.println("So many errors so little time");

    } catch (SAXException e) {
    System.out.println(e.toString());
    } catch (IOException e) {
    System.out.println(e.toString());
    }catch (Exception e) {
    e.printStackTrace();
    }
    }
    private static class MyErrorHandler extends DefaultHandler {

    public void warning(SAXParseException e) throws SAXException {
    System.out.println("Warning: ");
    printInfo(e);
    }
    public void error(SAXParseException e) throws SAXException {
    System.out.println("Error: ");
    printInfo(e);
    }
    public void fatalError(SAXParseException e) throws SAXException {
    System.out.println("Fattal error: ");
    printInfo(e);
    }
    private void printInfo(SAXParseException e) {
    sErrorBuffer.append("\n Public ID: "+e.getPublicId());
    sErrorBuffer.append("\n System ID: "+e.getSystemId());
    sErrorBuffer.append("\n Line number: "+e.getLineNumber());
    sErrorBuffer.append("\n Column number: "+e.getColumnNumber());
    sErrorBuffer.append("\n Message: "+e.getMessage() + "\n");

    }
    }
    }

    <?xml version="1.0"?>
    <memories xmlns:xsi=
    "http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="memory.xsd">
    <memory tapeid="23412">
    <subdate>5/23/2001</subdate>
    <donor>John Baker</donor>
    <subject>Fishing off Pier 60</subject>
    </memory>
    <memory tapeid="23692">
    <subdate>8/01/2001</subdate>
    <donor>Elizabeth Davison</donor>
    <subject>Beach volleyball</subject>
    </memory>
    </memories>

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <xsd:element name="memories">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="memory" maxOccurs="unbounded"
    type="memoryType"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>

    <xsd:complexType name="memoryType">
    <xsd:sequence>
    <xsd:element name="media">
    <xsd:complexType>
    <xsd:attribute name="mediaid" type="xsd:string" />
    <xsd:attribute name="status" type="xsd:string" />
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="subdate" type="xsd:string"/>
    <xsd:element name="donor" type="xsd:string"/>
    <xsd:element name="subject" type="xsd:string"/>
    <xsd:element name="location" type="locationType" />
    </xsd:sequence>
    <xsd:attribute name="tapeid" type="xsd:string" />
    <xsd:attribute name="status" type="xsd:string" />
    </xsd:complexType>

    <xsd:complexType name="locationType">
    <xsd:choice>
    <xsd:element name="description" type="xsd:string" />
    <xsd:element name="place" type="xsd:string" />
    </xsd:choice>
    </xsd:complexType>
    </xsd:schema>
     
    motoman, Oct 15, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,551
    Markus
    Nov 23, 2005
  2. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,269
    Stanimir Stamenkov
    Apr 25, 2005
  3. Valery
    Replies:
    0
    Views:
    584
    Valery
    Aug 30, 2007
  4. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    240
    Gregory Toomey
    Apr 23, 2004
  5. Replies:
    5
    Views:
    1,030
    Brian McCauley
    Nov 29, 2006
Loading...

Share This Page