3

The symbols: hyphen -, under-score _ and period . are allowed in element name. The XML example is valid.

<?xml version="1.0" encoding="UTF-8"?>
<student>
   <first-name>George</first-name>
   <phone.mobile>(011) 123-4567</phone.mobile>
   <native_language>English</native_language>
   <city />
</student>

Is there any other symbol that is also allowed in XML element name?

Tandilashvili
  • 83
  • 1
  • 5
  • 2
    Surely you could Google/Bing this question? Please see: [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/1422451) – Parfait Jan 02 '21 at 00:48

2 Answers2

8

The characters allowed in XML element names are given by the W3C XML BNF for component names:

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]
NameChar      ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] |
                  [#x203F-#x2040]
Name          ::= NameStartChar (NameChar)*

See also


kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Good to know the formal definition. It's surprising to see the many Unicode code-point ranges as acceptable start characters. In practice, at least in .NET, only _some_ of them work, namely accented Latin letters (e.g, `Á`) and _some_ Greek letters (e.g, `Π` works, whereas `Ͱ` does not). Do you know why? – mklement0 Nov 28 '22 at 21:59
  • 1
    @mklement0: Sorry, I wasn't involved in the standardization process behind the characters allowed in XML component names and do not know the rationale, nor do I know why .NET might not support the full range. – kjhughes Nov 29 '22 at 02:42
0

Right: Letter, digit, hyphen, underscore and period.

One may use any Unicode letter.

And of course one may prefix the names with name space + colon.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138