• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Creating a schema which imports some other schemas

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
davidjava
Asked:
davidjava
  • 2
1 Solution
 
b1xml2Commented:
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
 
davidjavaAuthor Commented:
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
 
b1xml2Commented:
<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

Industry Leaders: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now