扩展 complexType 时是否混合继承? [英] Is mixed inherited when a complexType is extended?

查看:29
本文介绍了扩展 complexType 时是否混合继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在架构中有以下内容:

I have the following in a schema:

<xs:element name="td">
   <xs:complexType>
     <xs:complexContent>
       <xs:extension base="cell.type"/>
    </xs:complexContent>
  </xs:complexType>
</xs:element>

<xs:complexType name="cell.type" mixed="true">
  <xs:sequence minOccurs="0" maxOccurs="unbounded">
    <xs:element ref="p"/>
  </xs:sequence>
</xs:complexType>

有些解析器允许直接在元素中使用 PCDATA,而其他解析器则不允许.XSD 建议 (3.4.2) 中有一些说明,当复杂类型具有复杂内容,并且两者都没有混合属性时,有效混合为假.这意味着混合内容可能有效的唯一方式是 cell.type 的扩展名是否导致 mix="true" 被继承.

Some parsers allow PCDATA directly in the element, while others don't. There's something in the XSD recommendation (3.4.2) that says when a complex type has complex content, and neither has a mixed attribute, the effective mixed is false. That means the only way mixed content could be in effect is if the extension of cell.type causes the mixed="true" to be inherited.

更熟悉模式的人能否评论正确的解释?

Could someone more familiar with schemas comment on the correct interpretation?

(顺便说一句:如果我可以控制架构,我会将 mix="true" 移到元素定义中,但这不是我的要求.)

(BTW: if I had control of the schema I would move the mixed="true" to the element definition, but that's not my call.)

推荐答案

任何阅读我问题的人都可能想阅读 这个 主题也是(来自 Damien).看来我的回答并不完全正确:解析器/验证器不会以相同的方式处理基础/派生元素上的混合属性声明.

Anyone reading my question might want to read this thread also (by Damien). It seems my answer isn't entirely right: parsers/validators don't handle mixed attribute declarations on base/derived elements the same way.

关于扩展复杂类型,的第 1.4.3.2.2.1 小节W3C 的 第 1 部分中的第 3.4.6 节http://www.w3.org/TR/xmlschema-1" rel="nofollow noreferrer">XML Schema 规范说

Concerning extended complex types, sub-section 1.4.3.2.2.1 of section 3.4.6 in part 1 of W3C's XML Schema specification says that

[派生和基础] {content type} 必须混合,或者两者都必须是元素.

Both [derived and base] {content type}s must be mixed or both must be element-only.

所以是的,它是继承的(或者更像是你不能覆盖它——最终是一样的).

So yes, it is inherited (or more like you cannot overwrite it—same thing in the end).

基本上,您所描述的是所需的(就我而言)最合乎逻辑的行为.

Basically, what you've described is the desired (and as far as I'm concerned) the most logical behavior.

我已经创建了一个简单的模式来使用 Eclipse 的 XML 工具运行一个小测试.

I've created a simple schema to run a little test with Eclipse's XML tools.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="c">
    <xs:complexType>
      <xs:complexContent mixed="false">
        <xs:extension base="a"/>
      </xs:complexContent>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="a" mixed="true">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="b"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

上述模式是有效的,因为 Eclipse 和 W3C 的官方"XML 模式验证器都没有注意到它的任何问题.

The above schema is valid, in the sense that not Eclipse's nor W3C's "official" XML Schema validator notices any issues with it.

以下 XML 通过对上述架构的验证.

The following XML passes validation against the aforementioned schema.

<?xml version="1.0" encoding="UTF-8"?>
<c xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd">
  x
  <b/>
  y
</c>

所以基本上你不能覆盖复杂基类型的混合性.为了进一步支持这一说法,请尝试交换基础类型和派生类型的混合性.在这种情况下,XML 无法验证,因为派生类型不会被混合,因为它(再次)不能覆盖基的混合性.

So basically you cannot overwrite the mixedness of a complex base type. To support this statement further, try and swap the base and dervied types' mixedness. In that case the XML fails to validate, because the derived type won't be mixed as it (yet again) cannot overwrite the base's mixedness.

你也说过

有些解析器允许直接在元素中使用 PCDATA,而其他解析器则不允许

Some parsers allow PCDATA directly in the element, while others don't

澄清您在谈论哪些解析器并没有什么坏处.好的 解析器在遇到混合内容时不应该失败.给定正确架构的验证解析器将在架构不允许的情况下遇到混合内容时失败.

It couldn't hurt to clarify which parsers are you talking about. A good parser shouldn't fail when it encounters mixed content. A validating parser, given the proper schema, will fail if it encounters mixed content when the schema does not allow it.

这篇关于扩展 complexType 时是否混合继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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