XSD Validation Error (Import schema)

This should cover W3C XML Schema, Relax NG and DTD related problems.
mamtarun1828
Posts: 1

XSD Validation Error (Import schema)

Mon Dec 17, 2012 1:04 pm

Hi 

I need some help regarding XML Schema Validation. 

I am struck with XSD validation issues when I try to reference other schema in base schema.

I am getting the error message "src-resolve: Cannot resolve the name 'cmn:MasterNode' to a(n) 'type definition' component."

Stripped Version of Schema Design is listed below

1. Base Schema file (v21.xsd) references element "MasterNode" of the schema v2_refer.xsd . On validation of schema , gets the error message as listed above
<xs:schemaattributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:cmn="file:///Users/tarun/schema/v2refer/v2_refer" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="file:///Users/tarun/schema">

<xs:importnamespace="file:///Users/tarun/schema/v2refer/v2_refer"schemaLocation="/Users/tarun/schema/v2refer/v2_refer.xsd"/>

<xs:elementname="TestMaster"type="cmn:MasterNode"></xs:element>
<xs:elementname="ROOT">

<xs:complexType>
<xs:sequence>
<xs:elementname="NOD">
<xs:complexType>
<xs:sequence>
<xs:elementname="Nod"maxOccurs="10">

</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>


2) Schema that is being referenced is defined below
<xs:schemaattributeFormDefault="unqualified"elementFormDefault="qualified" 
targetNamespace="file:///Users/tarun/schema/v2refer/v2_refer"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:cmn="file:///Users/tarun/schema/v2refer/v2_refer"
>
  <xs:elementname="MasterNode">
    <xs:complexType>
      <xs:sequence>
        <xs:elementtype="xs:string"name="Tomcat"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

 
</xs:schema>

Any help will be highly appreciated.


Thanks,
Tarun
adrian
Posts: 2337

Re: XSD Validation Error (Import schema)

Mon Dec 17, 2012 1:54 pm

Hi,

You're referring to a type that does not exist.
<xs:element name="TestMaster" type="cmn:MasterNode"></xs:element>
What does exist with that name (MasterNode) is an element, NOT a type:
<xs:element name="MasterNode">


So, rewrite v2_refer.xsd as:

Code: Select all

    <xs:complexType name="MasterNodeType">
        <xs:sequence>
            <xs:element type="xs:string" name="Tomcat"/>
        </xs:sequence>
    </xs:complexType>
   
    <xs:element name="MasterNode" type="cmn:MasterNodeType"/>

and in the main schema refer the type:

Code: Select all

<xs:element name="TestMaster" type="cmn:MasterNodeType"/>


BTW, file URLs as namespaces are rather uncommon (e.g. file:///Users/tarun/schema/v2refer/v2_refer). You might want to use something simpler. It doesn't have to be an existing URL (or even an URL).
e.g. "http://v2refer.ns" or "my.ns.v2"

For schemaLocation you might want to use a relative path instead, especially if the schemas are kept together in close proximity (same or adjacent folder).

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests