Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespace " Is not available to be referenced in this schema

Tags:

xml

xsd

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.

like image 776
deathismyfriend Avatar asked Jan 15 '14 13:01

deathismyfriend


People also ask

What is namespace in XSD schema?

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.

How do I add namespace prefix to XML element?

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 .

What is namespace URI in XML?

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.

How do you add a namespace to an XML element in Java?

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".


1 Answers

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>
like image 85
forty-two Avatar answered Sep 30 '22 02:09

forty-two