Numeric ID type in XML Schema

I need to define an ID type with a given pattern using XML schema. What I am so far is:

  <xs:simpleType name="myid">
    <xs:restriction base="xs:ID">
      <xs:pattern value="[A-Za-z0-9_-]+"/>
    </xs:restriction>
  </xs:simpleType>

      

This works, except it is <myid>00123_45678<myid>

not checked , for example . Apparently the base type xs: ID requires its own values ​​for XML-unqualified names (xs: NCName). In particular, identifiers may not start with numbers.

Is there an alternative way of defining the document ID using XML Schema that allows a numeric first character?

+3


source to share


1 answer


Derive your type from xsd: string or xsd: token or xsd: NMTOKEN, not an identifier. The xsd: ID type introduces XML naming rules and therefore requires the value to begin with the namestart character.



Restore the uniqueness constraint by adding an xs: unique declaration to the corresponding parent element.

+2


source







All Articles