在XSD中定义和重用限制

Dra*_*nix 4 xml xsd restriction

在我的XSD中,我有一个经常使用的限制。在多个地方使用相同的限制,更新时可能会忽略它。我知道有工具(查找/替换),但是我认为最好在全局定义这些限制。这样,我们只需要在一个地方更改它,而不是x倍。

我还有一个额外的问题,就是元素的名称总是不同,并且无法更改它(例如long_summary,short_summary等)

XSD的设置

<xs:schema>
    <xs:complexType name="eventType">
        <xs:sequence>
            <xs:element name="short_summary">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:pattern value="([\p{L}\p{M}\p{N}\p{P}\p{Z}\p{S}\p{C}]+)?"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name="long_summary">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:pattern value="([\p{L}\p{M}\p{N}\p{P}\p{Z}\p{S}\p{C}]+)?"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
         </xs:sequence> 
    </xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

基本上,我只想定义([\p{L}\p{M}\p{N}\p{P}\p{Z}\p{S}\p{C}]+)?一次限制,并将其重用于short_summary和long_summary。

任何建议或指示,不胜感激。同时,我将进一步寻找,如果找到答案,我会将其放在此处。

Dra*_*nix 5

我的问题的答案:

全局限制

<xs:simpleType name="Text">
        <xs:restriction base="xs:string">
            <xs:pattern value="([\p{L}\p{M}\p{N}\p{P}\p{Z}\p{S}\p{C}]+)?"/>
        </xs:restriction>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)

在XSD中使用

....
<xs:element name="short_summary" type="Text"/>
<xs:element name="long_summary" type="Text"/>
....
Run Code Online (Sandbox Code Playgroud)