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.
Figure 1: Elements and attributes in XML Schema namespace are used to write an XML Schema document, which generates elements and attributes as defined by user and puts them in {target namespace}. This {target namespace} is then used to validate the XML instance.
Adding a namespace prefix to an elementThe XQuery expression in the following SELECT statement adds a namespace prefix to an element. The XQuery expression uses fn:QName to create a QName with a namespace binding. The XQuery let clause creates an empty element with name emp and namespace http://example.com/new .
A namespace name is a uniform resource identifier (URI). Typically, the URI chosen for the namespace of a given XML vocabulary describes a resource under the control of the author or organization defining the vocabulary, such as a URL for the author's Web server.
When using prefixes in XML, a namespace for the prefix must be defined. The namespace can be defined by an xmlns attribute in the start tag of an element. The namespace declaration has the following syntax. xmlns:prefix="URI".
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With