[jdom-interest] Problems with XML validation via schemas

Mike Peattie Mike.Peattie at xilinx.com
Mon Jun 3 15:48:39 PDT 2002


I'm attempting to run (what I thought was) a simple example of XML
validation via a schema using JDOM b8, Xerces 2.0.1, and JDK 1.4.  I
actually didn't write either the XML or the XSD myself- they are
examples from a tutorial I've found on the web.

__XML__
<?xml version="1.0"?>
<BookStore xmlns="http://www.books.org"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.books.org BookStore.xsd">
        <Book>
                <Title>My Life and Times</Title>
                <Author>Paul McCartney</Author>
                <Date>1998</Date>
                <ISBN>1-56592-235-2</ISBN>
                <Publisher>McMillin Publishing</Publisher>
        </Book>
        <Book>
                <Title>Illusions The Adventures of a Reluctant
Messiah</Title>
                <Author>Richard Bach</Author>
                <Date>1977</Date>
                <ISBN>0-440-34319-4</ISBN>
                <Publisher>Dell Publishing Co.</Publisher>
        </Book>
        <Book>
                <Title>The First and Last Freedom</Title>
                <Author>J. Krishnamurti</Author>
                <Date>1954</Date>
                <ISBN>0-06-064831-7</ISBN>
                <Publisher>Harper &amp; Row</Publisher>
        </Book>
</BookStore>

___
__XSD__
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.books.org"
            xmlns="http://www.books.org">
    <xsd:element name="BookStore">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="Book" maxOccurs="unbounded">
                  <xsd:complexType>
                      <xsd:sequence>
                          <xsd:element name="Title" type="xsd:string"
minOccurs="1" maxOccurs="1"/>
                          <xsd:element namef="Author" type="xsd:string"
minOccurs="1" maxOccurs="1"/>
                          <xsd:element name="Date" type="xsd:string"
minOccurs="1" maxOccurs="1"/>
                          <xsd:element name="ISBN" type="xsd:string"
minOccurs="1" maxOccurs="1"/>
                          <xsd:element name="Publisher"
type="xsd:string" minOccurs="1" maxOccurs="1"/>
                      </xsd:sequence>
                  </xsd:complexType>
              </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

___
__CODE__

SAXBuilder builder = new SAXBuilder(true);
Document doc = builder.build(new File("BookStore.xml"));


With what I thought was a trivial example, I still get an exception:

org.jdom.JDOMException: Error on line 2 of document
file:/C:/j2sdk1.4.0/xmltest/BookStore.xml: Element type "BookStore" is
not declared.

 at org.jdom.input.SAXBuilder.build(SAXBuilder.java:363)

 at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)

 at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)

the rest of the stack trace is application specific.  I heard there was
a problem with Xerces once upon a time (searching this list's archives)
but I could not find confirmation of any fix, or it's existence in
2.0.1.  Has anyone seen this before, and/or gotten around it?  I tried
to use one of the simplest XML examples I could find, but still have
problems.

Thanks,

Mike Peattie





More information about the jdom-interest mailing list