Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Home » Tip Bank » XML
Language: .NET
Expertise: Intermediate
Jun 5, 2007



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Special Characters in XML Element and Attribute Names

When creating XML files, sometimes there are fields (elements/attributes) where you need to use special characters like space, &, <, etc. However, according to the XML specification, these are invalid.

.NET provides the EncodeName and DecodeName methods in the XMLConvert class for just this purpose. These methods encode and decode the special characters and convert them to valid XML values.

For instance:

//To create an element with the name "Test Level"
xmlTextWriter.WriteElementString("Test Level", "600");
//would throw an error on trying to view it

//use EncodeName() instead
xmlTextWriter.WriteElementString(XmlConvert.EncodeName("Test Level"), "600");

Note: Always use XmlConvert.

Srinath MS
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date