title: How to check if string is a valid XML element name?
body: <p>I need a regex or a function in PHP that will validate a string to be a good XML element name.</p>
  
  <p>Form w3schools:</p>
  
  <blockquote>
    <p>XML elements must follow these naming
    rules:</p>
    
    <ol>
    <li>Names can contain letters, numbers, and other characters</li>
    <li>Names cannot start with a number or punctuation character</li>
    <li>Names cannot start with the letters xml (or XML, or Xml, etc)</li>
    <li>Names cannot contain spaces</li>
    </ol>
  </blockquote>
  
  <p>I can write a basic regex that will check for rules 1,2 and 4, but it won't account for all punctuation allowed and won't account for 3rd rule</p>
  
  <pre><code>\w[\w0-9-]
  </code></pre>
  
  <h3>Friendly Update</h3>
  
  <p>Here is the more authoritative source for <a href="http://www.w3.org/TR/REC-xml/#NT-NameChar" rel="noreferrer">well-formed XML Element names</a>:</p>
  
  <p>Names and Tokens</p>
  
  <pre><code>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)*
  </code></pre>
  
  <p>Also a separate non-tokenized rule is specified:</p>
  
  <blockquote>
    <p>Names beginning with the string "xml", or with any string which would match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization in this or future versions of this specification.</p>
  </blockquote>