0

I try execute such a code sample.

var xmlDocument = new XmlDocument();
documentTagName = "testName)"
XmlNode headerElement = xmlDocument.CreateElement(documentTagName);

Of cource I get XmlException:

The ')' character, hexadecimal value 0x... (doesn't matter), cannot be included in a name

Because I have ) symbol in documentTagName. And of cource I'll get the same exception if documentTagName would be like this:

documentTagName = "testName("

or like this:

documentTagName = "testName:"

Because all of these characters ('(' , ')' , ':') are invalid for the xml tag name. But I check many links (and even this) and cannot find the list of all invalid characters for xml tag name. Can anybody help me?

monstr
  • 1,680
  • 1
  • 25
  • 44
  • WC3 XML Spec, element name section: http://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name. It's more complex than a simple sequence (unicode also comes in). There are some RegEx's which will tell you if it's a 'legal'. (see http://stackoverflow.com/questions/2519845/how-to-check-if-string-is-a-valid-xml-element-name) – Marvin Smit Oct 29 '14 at 08:24
  • @Marvin Smit, In your link I see only this `PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]` – monstr Oct 29 '14 at 08:36
  • 1st link: w3.org link => Official XML specifications. Starts at "Names and Tokens". 2nd link: Shows essentially same question but for PHP. Regex's shown there are still useful. – Marvin Smit Oct 29 '14 at 08:41
  • @Marvin Smit, I need the **list of illegal characters**, but you suppose me rules how to form name of xml node corretly or check the name correctness with Regex. Thx, but it is not quite what I want. – monstr Oct 29 '14 at 08:47
  • There isn't a "list of illegal characters". It's a complex sequence where some character are allowed from position 2, but not as first char. etc... – Marvin Smit Oct 29 '14 at 08:55

0 Answers0