[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 version="1.0"?>
<BookStore xmlns="http://www.books.org"
           xsi:schemaLocation="http://www.books.org BookStore.xsd">
                <Title>My Life and Times</Title>
                <Author>Paul McCartney</Author>
                <Publisher>McMillin Publishing</Publisher>
                <Title>Illusions The Adventures of a Reluctant
                <Author>Richard Bach</Author>
                <Publisher>Dell Publishing Co.</Publisher>
                <Title>The First and Last Freedom</Title>
                <Author>J. Krishnamurti</Author>
                <Publisher>Harper &amp; Row</Publisher>

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    <xsd:element name="BookStore">
                <xsd:element name="Book" maxOccurs="unbounded">
                          <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"/>


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


Mike Peattie

More information about the jdom-interest mailing list