[英]XML Schema: Element with attributes containing “restricted” text only
I want to define an element with some restricted text and an attribute 我想定义一个带有一些受限文本和一个属性的元素
<some_element my_attr="data">some restricted text</some_element>
How can I create an element like this? 如何创建这样的元素?
I tried: 我试过了:
<complexType>
<simpleContent>
<restriction base="string">
<pattern value="AAA"></pattern>
<attribute name="newattr" type="string"></attribute>
</restriction>
</simpleContent>
</complexType>
But getting error msg: 但是收到错误消息:
Complex Type Definition Representation Error for type '#AnonType_childparent'. 类型“ #AnonType_childparent”的复杂类型定义表示错误。 When is used, the base type must be a complexType whose content type is simple, or, only if restriction is specified, a complex type with mixed content and emptiable particle, or, only if extension is specified, a simple type. 使用时,基本类型必须是其内容类型为simple的complexType,或者(仅在指定了限制的情况下)是具有混合内容和可清空粒子的复杂类型,或者(仅在指定了扩展名的情况下)简单类型。 'string' satisfies none of these conditions. “字符串”不满足这些条件。
And then tried something like this 然后尝试这样的事情
<complexType>
<complexContent>
<extension base="string">
<attribute name="attr" type="string"></attribute>
</extension>
</complexContent>
</complexType>
This time error was (This time I didn't add any restriction; this was for test purpose only): 这次错误是(这次我没有添加任何限制;这仅出于测试目的):
Complex Type Definition Representation Error for type '#AnonType_childparent'. 类型“ #AnonType_childparent”的复杂类型定义表示错误。 When is used, the base type must be a complexType. 使用时,基本类型必须为complexType。 'string' is a simpleType. 'string'是一个simpleType。
I am not getting clearly what the errors are implying? 我没有弄清楚这些错误意味着什么? Is there some better explanation of error text available? 有没有更好的错误文本说明?
Your question is more or less a duplicate of this question (just answered it). 您的问题或多或少是该问题的重复部分(刚刚回答了该问题)。
Think in these terms: 用以下术语思考:
This post on SO shows you an end-to-end example, of the above explanation. SO上的帖子向您展示了上述说明的端到端示例。 For your particular case: 对于您的特定情况:
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:simpleType name="tSomeRestrictedText">
<xsd:restriction base="xsd:string">
<xsd:pattern value="AAA"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="some_element">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="tSomeRestrictedText">
<xsd:attribute name="my_attr" type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.