Solved

Creating a schema which imports some other schemas

Posted on 2002-05-15
3
235 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

734 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