【问题标题】:Extend a public XSD schema with new attribute使用新属性扩展公共 XSD 架构
【发布时间】:2021-06-26 20:16:27
【问题描述】:

我想用名为 newAttr 的新属性扩展 the existing XSD schematrans-unit 元素)。

因此,原始架构具有以下名为 trans-unit 的元素,我想对其进行扩展:

<xsd:element name="trans-unit">
    <xsd:complexType>
      <xsd:attribute name="id" type="xsd:string" use="required"/>
      <xsd:attribute name="approved" type="xlf:AttrType_YesNo" use="optional"/>
      <xsd:anyAttribute namespace="##other" processContents="strict"/>
    </xsd:complexType>
    <xsd:unique name="U_tu_segsrc_mid">
      <xsd:selector xpath="./xlf:seg-source/xlf:mrk"/>
      <xsd:field xpath="@mid"/>
    </xsd:unique>
    <xsd:keyref name="KR_tu_segsrc_mid" refer="xlf:U_tu_segsrc_mid">
      <xsd:selector xpath="./xlf:target/xlf:mrk|./xlf:alt-trans"/>
      <xsd:field xpath="@mid"/>
    </xsd:keyref>
</xsd:element>

为此,我创建了重新定义原始架构的新架构:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:oasis:names:tc:xliff:document:1.2" xml:lang="en">
    <xsd:redefine schemaLocation="http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd">
        <xsd:complexType name="trans-unit">
            <xsd:extension base="trans-unit">
                <xsd:attribute name="newAttr" type="xsd:string" use="optional"/>
            </xsd:extension>
        </xsd:complexType>
    </xsd:redefine>
</xsd:schema>

但是,不幸的是,使用此扩展架构验证文件失败并出现以下错误:

'attribute' 不是有效的孙元素。元素的子元素必须具有或后代,具有引用自身的“基本”属性。

我不确定我应该如何进行扩展。如果有人能解释我做错了什么,那就太好了。

【问题讨论】:

    标签: xml xsd xliff redefine


    【解决方案1】:

    原始架构具有以下称为 trans-unit 的元素,我想扩展它

    XML Schema 不允许重新定义元素声明。见https://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#modify-schema

     <redefine
      id = ID
      schemaLocation = anyURI
      {any attributes with non-schema namespace . . .}>
      Content: (annotation | (simpleType | complexType | group | attributeGroup))*
    </redefine>
    

    请注意,'element' 不是 xs:redefine 内容的选项之一。

    我想提供帮助,并提出一些扩展此架构的方法。但是公共模式似乎是为了禁止扩展而设计的。如果复杂类型是全局的,那么它可以扩展(比重新定义好得多,顺便说一句)。但复杂类型是本地定义的,因此不能以任何方式修改。

    我想不出任何方法可以使用 XML Schema 的扩展机制来更改此元素声明的类型定义。我认为您需要修改 XSD。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      • 2016-07-17
      • 2014-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-10
      相关资源
      最近更新 更多