Solved

Creating a schema which imports some other schemas

Posted on 2002-05-15
3
230 Views
Last Modified: 2013-11-19
I have 3 basic schemas which both Xerces-C++ and XMLSpy claim to be valid: Nikon.xsd, Olympus.xsd and Pentax.xsd.

Then I try to create a new schema (Camera.xsd) which imports the definitions of the 3 basic schemas in order to create a more complex new element. Both Xerces and XMLSpy show an error which says that types with name nikon:body_type, olympus:lens_type and pentax:manual_adapter_type have not been defined in current nor included/imported schemas.

I cannot find the error which prevents the new schema from being properly validated. Some advice would be appreciated.

Best regards,
David

--------------------- Nikon.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.nikon.com"
            targetNamespace="http://www.nikon.com"
            elementFormDefault="qualified"
            attributeFormDefault="qualified">
    <xsd:element name="body_type">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="description" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

--------------------- Olympus.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.olympus.com"
            targetNamespace="http://www.olympus.com"
            elementFormDefault="qualified"
            attributeFormDefault="qualified">
    <xsd:element name="lens_type">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="zoom" type="xsd:string"/>
                <xsd:element name="f-stop" type="xsd:decimal"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

--------------------- Pentax.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.pentax.com"
            targetNamespace="http://www.pentax.com"
            elementFormDefault="qualified"
            attributeFormDefault="qualified">
    <xsd:element name="manual_adapter_type">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="speed" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

--------------------- Camera.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.camera.org"
            targetNamespace="http://www.camera.org"
            xmlns:nikon="http://www.nikon.com"
            xmlns:olympus="http://www.olympus.com"
            xmlns:pentax="http://www.pentax.com"
            elementFormDefault="qualified"
            attributeFormDefault="qualified">
    <xsd:import namespace="http://www.nikon.com"
                schemaLocation="Nikon.xsd"/>
    <xsd:import namespace="http://www.olympus.com"
                schemaLocation="Olympus.xsd"/>
    <xsd:import namespace="http://www.pentax.com"
                schemaLocation="Pentax.xsd"/>
    <xsd:element name="camera">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="body" type="nikon:body_type"/>
                <xsd:element name="lens" type="olympus:lens_type"/>
                <xsd:element name="manual_adapter" type="pentax:manual_adapter_type"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

0
Comment
Question by:davidjava
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
b1xml2 earned 200 total points
ID: 7011529
The reason why you cannot suucessfully import the other xsds in your camera xsd is because while you specify the type and point to a xsd:complexType element, you have instead the xsd:element with the name, and no xsd:complexType element with the name.

pentax.xsd
==========
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns="http://www.pentax.com"
  targetNamespace="http://www.pentax.com"
  elementFormDefault="qualified"
  attributeFormDefault="qualified">
   <xsd:complexType name="manual_adapter_type">
      <xsd:sequence>
        <xsd:element name="speed" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
</xsd:schema>


olympus.xsd
===========
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns="http://www.olympus.com"
  targetNamespace="http://www.olympus.com"
  elementFormDefault="qualified"
  attributeFormDefault="qualified">
  <xsd:complexType name="lens_type">
    <xsd:sequence>
      <xsd:element name="zoom" type="xsd:string"/>
      <xsd:element name="f-stop" type="xsd:decimal"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>


nikon.xsd
==========
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns="http://www.nikon.com"
  targetNamespace="http://www.nikon.com"
  elementFormDefault="qualified"
  attributeFormDefault="qualified">
   <xsd:complexType name="body_type">
    <xsd:sequence>
      <xsd:element name="description" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>


camera.xsd
===========
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns="http://www.camera.org"
  targetNamespace="http://www.camera.org"
  xmlns:nikon="http://www.nikon.com"
  xmlns:olympus="http://www.olympus.com"
  xmlns:pentax="http://www.pentax.com"
  elementFormDefault="qualified"
  attributeFormDefault="qualified">
  <xsd:import  namespace="http://www.nikon.com" schemaLocation="nikon.xsd"/>
  <xsd:import namespace="http://www.olympus.com" schemaLocation="olympus.xsd"/>
  <xsd:import namespace="http://www.pentax.com" schemaLocation="pentax.xsd"/>
  <xsd:element name="camera">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="body" type="nikon:body_type"/>
        <xsd:element name="lens" type="olympus:lens_type"/>
        <xsd:element name="manual_adapter" type="pentax:manual_adapter_type"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

camera.asp (to validate)
========================
<%@language="JScript"%>
<object id="oXML" progid="Msxml2.DOMDocument.4.0" runat="server"></object>
<object id="oSchema" progid="Msxml2.XMLSchemaCache.4.0" runat="server"></object>
<%
try {
  oXML.async = false;
  oSchema.add("http://www.camera.org",Server.MapPath("xsd/camera.xsd"));
  oXML.schemas = oSchema;
  if (! (oXML.load(Server.MapPath("xml/camera.xml")))) {
    throw new Error(oXML.parseError.errorCode,"Parser Error::" + oXML.parseError.reason);
  } else {
    throw new Error(0,"Parser Success::");
  }
} catch (e) {
  Response.Write(e.number + " - " + e.message);
}
%>

camera1.xml
==========
<?xml version="1.0" encoding="iso-8859-1"?>
<camera
  xmlns="http://www.camera.org"
  xmlns:pentax="http://www.pentax.com"
  xmlns:nikon="http://www.nikon.com"
  xmlns:olympus="http://www.olympus.com">
<body>
  <nikon:description>I am here</nikon:description>
</body>
<lens>
  <olympus:zoom>10x</olympus:zoom>
  <olympus:f-stop>10.45</olympus:f-stop>
</lens>
<manual_adapter>
  <pentax:speed>100MHz</pentax:speed>
</manual_adapter>
</camera>




Result 1
========
0 - Parser Success::


camera2.xml
===========
<?xml version="1.0" encoding="iso-8859-1"?>
<camera
  xmlns="http://www.camera.org"
  xmlns:pentax="http://www.pentax.com"
  xmlns:nikon="http://www.nikon.com"
  xmlns:olympus="http://www.olympus.com">
<body>
  <nikon:description>I am here</nikon:description>
</body>
<lens>
  <olympus:zoom>10x</olympus:zoom>
  <olympus:f-stop>10.45a</olympus:f-stop>
</lens>
<manual_adapter>
  <pentax:speed>100MHz</pentax:speed>
</manual_adapter>
</camera>

Result 2
=========
-1072897660 - Parser Error::The value of '10.45a' is invalid according to its data type.
The element: '{http://www.olympus.com}f-stop'  has an invalid value according to its data type.

Notes
=====
Validation thus is successfully carried out.
0
 

Author Comment

by:davidjava
ID: 7011718
I just noticed the error at the same time than you b1xml2, but I still do not understant the difference between pointing to an element and pointing to a type. Could you explain please?
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7011885
<xsd:element name="body" type="nikon:body_type"/>
 here the xsd:element body points to a xsd:complexType or xsd:simpleType element having the name body_type. It does not point to xsd:elements. xsd:complexTypes and xsd:simpleTypes do not appear as elements outright.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now