XML DTD Specify a cdata/text pattern for attribute

纵饮孤独 提交于 2019-12-11 09:35:01

问题


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

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

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

<!ATTLIST MyElement 
    myattribute "*,*"
>

(I know, for this example two attributes X and Y would certainly be better, but that's just to highlight what I want to do)

Thanks


回答1:


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>

The value in xs:pattern is a regular expression.



来源:https://stackoverflow.com/questions/11760608/xml-dtd-specify-a-cdata-text-pattern-for-attribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!