Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 14th, 2006, 05:13 PM
Authorized User
 
Join Date: Feb 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML schema validation problems

Why am I getting the following error ?

Results from W3C XML Schema validation:
Validation error:
Reason: The element 'Books' is used but not declared in the DTD/Schema.
Error code: -1072898035

--------------------------------------------------------------------
My XML doc

<?xml version ='1.0' ?>
<!DOCTYPE Books SYSTEM "BooksDTD.dtd">
<Books
    xmlns="http://madeupbookshop.com/books"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://madeupbookshop.com/books books.xsd">
    <Book>
        <ISBN>12345</ISBN>
        <PUBLISHER>Wrok</PUBLISHER>
        <AUTHOR>
        <FIRST_NAME>William</FIRST_NAME>
        <LAST_NAME>Blake</LAST_NAME>
        </AUTHOR>
        <TITLE>Walk in the wood</TITLE>
        <EDITION>First edition</EDITION>
        <PRICE>$99.95</PRICE>
        <PAGES>500</PAGES>
        <DATE_PUBLISHED>12 January 2004</DATE_PUBLISHED>
        <DESCRIPTION>I love trees</DESCRIPTION>
        <IMAGE>one.gif</IMAGE>
    </Book>
    <Book>
        <ISBN>12346</ISBN>
        <PUBLISHER>Wrok</PUBLISHER>
        <AUTHOR>
        <FIRST_NAME>Erric</FIRST_NAME>
        <LAST_NAME>Bird</LAST_NAME>
        </AUTHOR>
        <TITLE>eating to be large</TITLE>
        <EDITION>First edition</EDITION>
        <PRICE>$45.95</PRICE>
        <PAGES>600</PAGES>
        <DATE_PUBLISHED>16 January 2004</DATE_PUBLISHED>
        <DESCRIPTION>Be big and fat</DESCRIPTION>
        <IMAGE>two.jpg</IMAGE>
    </Book>
<Books>

--------------------------------------------------------------------------
I have the following schema

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
 xmlns:target="http://madeupbookshop.com/books"
 targetNamespace="http://madeupbookshop.com/books"
 elementFormDefault="qualified">
 <element name="Books" type="target:booksType" />
 <complexType name="AuthorType">
    <sequence>
      <element name="FIRST_NAME" type="string"/>
      <element name="LAST_NAME" type="string"/>
    </sequence>
 </complexType>
 <complexType name="bookType">
    <sequence>
       <element name="ISBN" type="string"/>
       <element name="PUBLISHER" type="string"/>
       <element name="AUTHOR" type="target:AuthorType"/>
       <element name="TITLE" type="string"/>
       <element name="EDITION" type="string"/>
       <element name="PRICE" type="string"/>
       <element name="PAGES" type="positiveInteger"/>
       <element name="DATE_PUBLISHED" type="string"/>
       <element name="DESCRIPTION" type="string"/>
       <element name="IMAGE" type="string"/>
    </sequence>
 </complexType>
 <complexType name="booksType">
     <sequence>
    <element name="Book" type="target:bookType" minOccurs="0" maxOccurs="unbounded" />
     </sequence>
 </complexType>
</schema>
 
Old February 14th, 2006, 05:42 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try removing the DOCTYPE, to see if that's causing the trouble; and correct <books> on line 36 to </books>. With that change the document is valid, so if you're still getting a problem then its in the way you are invoking the schema processor.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 15th, 2006, 09:57 AM
Authorized User
 
Join Date: Feb 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

On line 36 the line is </books>, <books> was a type for the forum.

You are correct DOCTYPE line is causing the problem. But my assignment I have to incuded both a schema and DTD validation. Is there away to include this line without the schema generating a error ?

Thanks for your help

Brendon

 
Old February 15th, 2006, 06:02 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Provided the document is valid both against the DTD and against the schema, it shouldn't be a problem. But invoking a parser to perform both validations becomes rather product-dependent, and I suspect the problem is related to the way you are running your chosen product.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Bewildering schema error in validation. overcast XSLT 5 August 26th, 2008 01:16 PM
Schema Validation markus2000 XSLT 1 June 22nd, 2006 08:23 AM
XML validation with Schema/DTD using JAXP Hendrik XML 0 December 28th, 2004 06:58 AM
XML Schema Validation without internet esp5a XML 1 September 5th, 2003 06:22 AM
XML, XML Schema, JavaScript, ASP cyberjames2003 XML 0 June 4th, 2003 04:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.