我可以扩展名称空间为空的xsd元素吗?

时间:2016-02-24 21:41:37

标签: xml xsd

我有一个我无法控制的架构。它看起来像这样。假设它位于名为Config.xsd的文件中。

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns=""
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           version="1.0">
  <xs:element name="config">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="configSettingOne" type="xs:string" minOccurs="1" maxOccurs="1" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

冷却。我想扩展config元素并在序列中添加更多片段。我被卡住了。我认为这与该名称空间在该名称空间上是空白的事实有关,但我尝试的每个变体都有视觉工作室抱怨某些东西不对。让我们假装这个文件被称为SpecializedConfig.xsd。我可以控制这个文件。

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="SpecializedConfig"
    xmlns:mstns="http://tempuri.org/SpecializedConfig.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  <xs:include schemaLocation="./Config.xsd"></xs:include>
  <xs:element name="extendedTestConfig">
    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="config">
          <xs:sequence>
            <xs:element name="configSettingTwo" type="xs:string" minOccurs="1" maxOccurs="1" />
          </xs:sequence>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:element>
</xs:schema>

我是否在这里遇到一些根本性的误解?或者这可以/不能这样做吗?谢谢!

1 个答案:

答案 0 :(得分:4)

嗯,一开始&#34;配置&#34;和&#34;配置&#34;是不同的名字。

下一个问题是你没有扩展元素,你扩展了类型。您已经提供了&#34; config&#34;元素是匿名类型,并且您无法扩展匿名类型,因为无法引用它。

首先使用命名类型:

<xs:element name="config" type="configType"/>
<xs:complexType name="configType">

然后你可以扩展它:

<xs:element name="extendedTestConfig" type="extendedConfigType"/>
<xs:complexType name="extendedConfigType">
   <xs:extension base="configType">

我认为它与命名空间无关。

相关问题