【问题标题】:XML DTD Specify a cdata/text pattern for attributeXML DTD 为属性指定 cdata/文本模式
【发布时间】:2012-08-01 23:00:09
【问题描述】:

有没有办法在 DTD 中为给定的属性指定“模式”。

示例:我想要一个名为 "position" 的属性,它是 "X,Y" 形式的字符串。

我想在我的 DTD 中包含类似于以下内容的内容:

<!ATTLIST MyElement 
    myattribute "*,*"
>

(我知道,对于这个例子,两个属性 X 和 Y 肯定会更好,但这只是为了突出我想要做的事情)

谢谢

【问题讨论】:

    标签: xml dtd


    【解决方案1】:

    您不能使用 DTD 指定模式。不过,您可以使用模式来做到这一点:

      <xs:element name="MyElement">
        <xs:complexType>
          <xs:attribute name="myattribute" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value="[^,]+,[^,]+"/>
                </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
        </xs:complexType>
      </xs:element>
    

    xs:pattern 中的value 是一个正则表达式。

    【讨论】:

    • 非常感谢。我想我可能会从 DTD 切换到模式,所以似乎更方便。
    猜你喜欢
    • 2010-09-26
    • 2013-12-26
    • 1970-01-01
    • 2014-07-11
    • 1970-01-01
    • 2017-05-24
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    相关资源
    最近更新 更多