XML DTD为属性指定cdata /文本模式 [英] XML DTD Specify a cdata/text pattern for attribute

查看:151
本文介绍了XML DTD为属性指定cdata /文本模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在DTD中,有没有一种方法可以为给定的属性指定一个模式。

Is there a way, in a DTD, to specify a "pattern" for a given attribute.

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

Example: I want to have an attribute called "position" which is a string of the form "X,Y".

我想在我的东西中放些东西DTD类似于:

I would like to have something in my DTD similar to:

<!ATTLIST MyElement 
    myattribute "*,*"
>

(我知道,对于此示例,两个属性X和Y肯定会更好,但是

谢谢

推荐答案

您不能使用DTD指定模式。不过,您可以使用以下模式进行操作:

You can't specify a pattern using DTD. You could do it using a schema though:

  <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 是一个正则表达式。

The value in xs:pattern is a regular expression.

这篇关于XML DTD为属性指定cdata /文本模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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