命名空间无法在此架构中引用 [英] Namespace " Is not available to be referenced in this schema

查看:28
本文介绍了命名空间无法在此架构中引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是 XML 模式的新手.(这是我的第一次尝试.)我不明白为什么我一直收到这个错误.命名空间无法在此架构中引用.

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 文件

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

推荐答案

您已经定义了一个目标命名空间,这意味着所有类型定义都将存在于该命名空间中.但是您对 Field1 的类型引用是指空命名空间.声明一个额外的命名空间:

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>

这篇关于命名空间无法在此架构中引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆