1

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

4

1 回答 1

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.

于 2012-08-01T15:00:09.520 回答