Check valid XML element name.
-
How to check if the string can be a valid XML element name? In other words, I'm looking for this kind of function:
bool XmlValidate(string name); XmlValidate("RightElement" ); // returns true XmlValidate("2 Wrong ,@# Element"); // returns false
-
How to check if the string can be a valid XML element name? In other words, I'm looking for this kind of function:
bool XmlValidate(string name); XmlValidate("RightElement" ); // returns true XmlValidate("2 Wrong ,@# Element"); // returns false
I'm not sure about a validate function, but you could do it this way: using System.Text.RegularExpressions; . . . // reg ex to validate an XML element name Regex reg = new Regex ( @"^(?!xml)[a-zA-Z]\w+$", RegexOptions.IgnoreCase ); if ( reg.IsMatch ( "STRING TO CHECK" ) ) { // do something with it } I did not verify the regular expression string against all possible errors (malformed element names), but you should be able to correct any mistakes or add characters that you want to be valid. I don't like to use anything other than what is already there. Hope this helps
-
How to check if the string can be a valid XML element name? In other words, I'm looking for this kind of function:
bool XmlValidate(string name); XmlValidate("RightElement" ); // returns true XmlValidate("2 Wrong ,@# Element"); // returns false
System.Xml.Serialization.CodeIdentifier.MakeValid()
just check if the returned value equals the input value. xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!