Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Creating a schema which imports some other schemas

Posted on 2002-05-15
3
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
b1xml2 earned 800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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 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:
The viewer will learn how to count occurrences of each item in an array.

649 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