How to check if string is a valid XML element name?
Posted
by xsaero00
on Stack Overflow
See other posts from Stack Overflow
or by xsaero00
Published on 2010-03-25T22:20:57Z
Indexed on
2010/03/25
22:23 UTC
Read the original article
Hit count: 406
I need a regex or a function in PHP that will validate a string to be a good XML element name.
Form w3schools:
XML elements must follow these naming rules:
- Names can contain letters, numbers, and other characters
- Names cannot start with a number or punctuation character
- Names cannot start with the letters xml (or XML, or Xml, etc)
- Names cannot contain spaces
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
\w[\w0-9-]
© Stack Overflow or respective owner