Mega Code Archive

 
Categories / C# / XML
 

Gets or sets a value indicating whether to normalize white space and attribute values

using System; using System.IO; using System.Xml; public class Sample{   public static void Main(){     string xmlFrag  =          @"<item attr1='  test A B C             1 2 3'/>           <item attr2='&#01;'/>";                              XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());     XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.Preserve);     XmlTextReader reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context);     // Show attribute value normalization.     reader.Read();     reader.Normalization = false;     Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1"));     reader.Normalization = true;     Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1"));     reader.Normalization = false;     reader.Read();     reader.MoveToContent();     Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr2"));     reader.Close();        } }