Solved

Creating a schema which imports some other schemas

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Parsing the XML data to SQL Server 4 59
XSLT list item selection criteria not working 12 26
XML Data Missing in PHP SimpleXML 8 44
AL3 Files 4 13
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

914 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

16 Experts available now in Live!

Get 1:1 Help Now