Validate the Element and Attribute Names

The XmlConvert class contains two methods that check the characters in a name and verifies that the name conforms to the rules set by the World Wide Web Consortium (W3C) in the Extensible Markup Language (XML) 1.0 (fourth edition) recommendation. The methods are:

The VerifyName method checks the characters and verifies that the name is valid. If the name is valid, it is returned by the method. If the name is not valid, an exception is thrown.

The VerifyNCName method does the same function as VerifyName. However, it takes the non-qualified name as its parameter.

The following code example shows how VerifyName checks the name abc before using the name as an element name.

Try
  writer.WriteStartElement(XmlConvert.VerifyName("abc"))

Catch e As XmlException
  Console.WriteLine(e.Message)
End Try
try {
  writer.WriteStartElement(XmlConvert.VerifyName("abc"));
}
catch (XmlException e){
  Console.WriteLine(e.Message);
}

See Also

Reference

EncodeName

EncodeLocalName

Concepts

Encode and Decode XML Element and Attribute Names and ID Values

Conversion of XML Data Types