XML validation error when using multiple schema files/namespaces

Posted by user129609 on Stack Overflow See other posts from Stack Overflow or by user129609
Published on 2010-03-19T21:28:04Z Indexed on 2010/03/19 21:31 UTC
Read the original article Hit count: 481

Filed under:
|
|

Hi,

I've been reading a ton about xml and learning a lot but I am stuck on one error.

I have a schema defined in multiple files and I can't get it to work. Here is an example

==================================

libraryBooks.xsd

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns="urn:MyNamespace"
  targetNamespace="urn:MyNamespace"
  elementFormDefault="qualified"
  >

  <xsd:element name="libraryBooks" type="libraryBooksType"/>

  <xsd:complexType name="libraryBooksType">
    <xsd:sequence>
       <xsd:any minOccurs="0"/>
    </xsd:sequence>
    <xsd:attribute name="name" type="xsd:string"/>
  </xsd:complexType>
</xsd:schema>

==================================

book.xsd

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns="urn:MyNamespace2"
  targetNamespace="urn:MyNamespace2"
  elementFormDefault="qualified"
  >

  <xsd:element name="book" type="booksType"/>

  <xsd:complexType name="bookType">
    <xsd:attribute name="title" type="xsd:string"/>
  </xsd:complexType>
</xsd:schema>

==================================

myXml.xml

<?xml version="1.0" encoding="utf-8" ?>
  <libraryBooks
     xmlns="urn:MyNamespace"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="urn:MyNamespace file:///C:/libraryBooks.xsd"

     name="CentralLibrary">
     <mn2:book 
        xmlns:mn2="file:///C:/book.xsd"
        title="How to make xml work the way I want">
     </mn2:book>
  </libraryBooks>

So the error I get would be "The 'file:///C:/book.xsd:book' element is not found". Any ideas? I'm almost certain it is something simple

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xml-schema