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

Can I extend an xsd element whose namespace is blank?

我有一个我无法控制的模式。它看起来像这样。假设它在一个名为 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>

酷。我想扩展配置元素并在序列中添加更多部分。我卡住了。我认为这与那个命名空间为空这一事实有关,但我尝试的每一个变体都有 visual studio 抱怨有些不对劲。假设这个文件名为 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>

我是不是在一些基本的误解下操作?或者这个/这个不可以吗?谢谢!

首先,"config" 和 "Config" 是不同的名称。

下一个问题是您扩展的不是元素,而是类型。您已经为您的 "config" 元素提供了匿名类型,并且您无法扩展匿名类型,因为无法引用它。

所以从使用命名类型开始:

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

然后你可以扩展它:

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

我不认为它与名称空间有任何关系。