【问题标题】:Namespace components are not referenceable命名空间组件不可引用
【发布时间】:2015-03-11 12:34:17
【问题描述】:

以下是我的部分 XML 架构

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Procurement" 
xmlns:tns="http://www.example.org/Procurement" elementFormDefault="qualified">

<element name="CountryCode">
    <simpleType>
        <restriction base="string">
            <enumeration value="US" />
            <enumeration value="DE" />
            <enumeration value="JP" />
        </restriction>
    </simpleType>
</element>

<element name="Address">
    <complexType>
        <sequence>
            <element name="Name" type="string" minOccurs="0"  />
            <element name="StreeName" type="string" minOccurs="0"  />
            <element name="City" type="string" />
            <element name="PostalCode" type="string" />
            <element name="Country" type="CountryCode" />
        </sequence>
    </complexType>
</element>

</schema>

当我尝试验证此架构时,我收到与 Country 类型中的 CountryCode 属性相关的错误,例如

错误解析组件。检测到“CountryCode”位于命名空间“http://www.w3.org/2001/XMLSchema”中,但该命名空间中的组件无法从架构文档“file:///C:/Eclipse/workspace/Procurement.xsd”中引用。

我做了一些研究,也看到过类似的帖子,但仍然无法解决这个问题。

有什么想法吗?

【问题讨论】:

    标签: xml xsd namespaces


    【解决方案1】:

    如果你想定义一个类型,你不能使用&lt;element&gt;。只需定义类型本身:

    <simpleType name="CountryCode">
      <restriction base="string">
        <enumeration value="US" />
        <enumeration value="DE" />
        <enumeration value="JP" />
      </restriction>
    </simpleType>
    

    在您的 XSD 中包含此类型意味着该类型将位于您的目标命名空间中。所以你需要这样引用它:

    <element name="Country" type="tns:CountryCode" />
    

    通过这两个修改,您的 XSD 应该是正确的。

    【讨论】:

      猜你喜欢
      • 2016-02-27
      • 1970-01-01
      • 1970-01-01
      • 2023-01-19
      • 2014-10-15
      • 2010-11-15
      • 2019-11-11
      • 2017-06-04
      • 1970-01-01
      相关资源
      最近更新 更多