xmlxsdxsd-validationw3cxml-validation

What are the correct xs:ID allowable id names?


I am trying to define an ID for id attribute of one of the tags. The documentation and xsd schema mandates to confirm the id set with xs:id.

I tried "ID_123" that worked but when I tried "123", it did not. I googled on the options and some examples a lot but couldn't find anything besides the text written here.

Could some please provide some examples here and what characters are allowed? To my understanding, any alphanumeric characters should work but seems there should be a combination of alphabets (or the word ID?) and numbers.


Solution

  • W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes defines xs:ID:

    3.4.8 ID

    [Definition:] ID represents the ID attribute type from[XML]. The ·value space· of ID is the set of all strings that ·match· the NCName production in [Namespaces in XML]. The ·lexical space· of ID is the set of all strings that ·match· the NCName production in [Namespaces in XML]. The ·base type· of ID is NCName.

    The NCName production limits the characters that can be used:

    [4] NCName ::= NCNameStartChar NCNameChar*    /* An XML Name, minus the ":" */
    [5] NCNameChar ::= NameChar - ':'
    [6] NCNameStartChar ::= NameStartChar - ':'
    [4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] |
                          [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | 
                          [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] |
                          [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] |
                          [#x10000-#xEFFFF]
    [4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | 
                      [#x0300-#x036F] | [#x203F-#x2040]
    

    Among the many constraints, note in particular that xs:IDs cannot have : characters anywhere in the name and cannot have a digit as the first character of the name.

    Therefore, your ID_123 is a proper NCName, but 123 is not because it begins with a digit.