Using the XmlTextReader's Namespaces Property

The Namespaces property provides read and write access to a value indicating whether the reader does namespace support. This property is set to true by default, which means that namespaces are supported. If namespace support is turned off, namespace prefixes are not resolved to their respective namespace URIs. Instead, the prefix and local name are considered the local name of the element. This property can be changed only before any read operation has been executed. This means that the XmlTextReader's ReadState property must equal ReadState.Initial. An InvalidOperationException is thrown if the reader is in any other state. Listing 10.4 shows the difference between a namespace-enabled reader and a namespace-disabled reader.

Listing 10.4.
C#
reader.Namespaces = true;
reader.MoveToContent();
MessageBox.Show("Local Name: " + reader.LocalName);
MessageBox.Show("Prefix: " + reader.Prefix);
MessageBox.Show("Namespace: " + reader.NamespaceURI);
reader.Close();

VB
reader.Namespaces = true
reader.MoveToContent();
MessageBox.Show("Local Name: " & reader.LocalName);
MessageBox.Show("Prefix: " & reader.Prefix);
MessageBox.Show("Namespace: " & reader.NamespaceURI);
reader.Close();

Input Data
<q1:BusinessObjects xmlns:q1="http://test.org">
<q1:BOOK>
<q1:Title>Peter's Chair</q1:Title>
<q1:Author>Ezar Jack Keats</q1:Author>
<q1:ISBN>0-596-00058-8</q1:ISBN>
</q1:BOOK>
<q1:MAG>
<q1:Title>Muscle Fitness</q1:Title>
<q1:ISBN>0-989-00053-8</q1:ISBN>
</q1:MAG>
</q1:BusinessObjects>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.17.140