Reputation: 2192
Hello I am very new to XML Schemas. (This is my first attempt.) I can't understand why I keep getting this error. Namespace " Is not available to be referenced in this schema.
This is the line i get the error on.
<sch:element name="Field1" type="naming"/>
XSD FILE
<?xml version="1.0" encoding="utf-8"?>
<sch:schema xmlns:sch="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://tempuri.org/MySchemaFile"
elementFormDefault="qualified">
<sch:element name="Root">
<sch:complexType>
<sch:sequence>
<sch:element name="Nodes" maxOccurs="unbounded">
<sch:complexType>
<sch:sequence>
<sch:element name="Field1" type="naming"/>
<sch:element name="Field2" type="sch:string"/>
<sch:element name="Field3" type="sch:integer" default="0"/>
<sch:element name="Field4" type="sch:string" default="0"/>
<sch:element name="Field5" type="sch:string"/>
<sch:element name="Field6" type="sch:string"/>
<sch:element name="Field7" type="sch:string" default="0"/>
<sch:element name="Field8" type="sch:string" default="0"/>
<sch:element name="Field9" type="sch:string" default="None"/>
</sch:sequence>
</sch:complexType>
</sch:element>
</sch:sequence>
</sch:complexType>
</sch:element>
<sch:simpleType name="naming">
<sch:restriction base ="sch:string">
<sch:minLength value="0"/>
<sch:maxLength value="5"/>
</sch:restriction>
</sch:simpleType>
</sch:schema>
Can anyone tell me what I am doing wrong ? Thanks to anyone that helps.
Upvotes: 6
Views: 11755
Reputation: 12817
You have defined a target namespace, which means that all type definitions will live in this namespace. But your type reference for Field1 refers to the empty namespace. Declare an extra namespace:
<sch:schema xmlns:sch="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://tempuri.org/MySchemaFile"
xmlns:tns="http://tempuri.org/MySchemaFile"
elementFormDefault="qualified">
and use that prefix when referring to types defined in your schema:
<sch:sequence>
<sch:element name="Field1" type="tns:naming"/>
<sch:element name="Field2" type="sch:string"/>
...
</sch:sequence>
Upvotes: 13