Understanding the Normalization Property


Understanding the Normalization Property

The Normalization property provides read and write access to a value that controls whether the reader performs white-space and attribute value normalization. A complete description of normalization is beyond the scope of this book. To learn more about normalization, you can read the Extensible Markup Language (XML) 1.0 recommendation, section "Attribute-Value Normalization," located at http://www.w3.org/TR/2000/REC-xml-20001006.html#AVNormalize. For now, you can think of normalization as the process of combining adjacent white-space nodes into one white-space node and replacing entity references with their resolved values. Because the .NET Compact Framework's XmlTextReader will not consume DTD information, resolving anything other than general entities, &#gt , is not possible. Furthermore, because general entities are always resolved independently of the Normalization property, normalization on the .NET Compact Framework is white-space normalization.

The default value of this property is false, which means that attribute and white-space normalization is not performed. The Normalization property can be changed at any time during parsing, but the change will take effect only when a subsequent read operation is executed. One side effect of turning off normalization is that character range checking for numeric entities is also switched off. This allows the reader to accept character entities in the range of � and  . With normalization enabled, the XmlTextReader would throw an XmlException when it encounters characters in this range. Listing 10.5 demonstrates how normalization property affects how the XmlTextReader parses XML data.

Listing 10.5
 C# public static void TestNormalization(bool normOn) {   string data =      @"<Root>      <Element attr='     &lt;Testing Normalization&gt;      New Line'/>       </Root>";      StringReader str = new StringReader(data);      XmlTextReader reader = new XmlTextReader(str);      reader.WhitespaceHandling=WhitespaceHandling.None;      reader.MoveToContent();      reader.ReadStartElement("Root");      reader.Normalization=normOn;      MessageBox.Show("Normalization On: " + normOn.ToString());      MessageBox.Show("attr's Value: " + reader.GetAttribute("attr"));        reader.Close(); } public static void Main(string[] args) {      // Test with normalization off      TestNormalization(false);      // Test with normalization on      TestNormalization(true); } VB Sub TestNormalization(ByVal normOn As Boolean)    Dim data As String    data = "<Root>" & _          "<Element attr='     &lt;Testing Normalization&gt; " & _          "New Line'/></Root>"   Dim str As New StringReader(data)   Dim reader As New XmlTextReader(str)   reader.WhitespaceHandling = WhitespaceHandling.None   reader.MoveToContent()   reader.ReadStartElement("Root")   reader.Normalization = normOn   MessageBox.Show("Normalization On: " & normOn.ToString())   MessageBox.Show("attr's Value: " & reader.GetAttribute("attr"))   reader.Close() End Sub Sub Main()    ' Test with normalization off     TestNormalization(False)    ' Test with normalization on     TestNormalization(True) End Sub 


Microsoft.NET Compact Framework Kick Start
Microsoft .NET Compact Framework Kick Start
ISBN: 0672325705
EAN: 2147483647
Year: 2003
Pages: 206

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net