XmlReader.Value Property
Assembly: System.Xml (in system.xml.dll)
/** @property */ public abstract String get_Value ()
public abstract function get Value () : String
Property Value
The value returned depends on the NodeType of the node. The following table lists node types that have a value to return. All other node types return String.Empty.| Node type | Value |
|---|---|
| Attribute | The value of the attribute. |
| CDATA | The content of the CDATA section. |
| Comment | The content of the comment. |
| DocumentType | The internal subset. |
| ProcessingInstruction | The entire content, excluding the target. |
| SignificantWhitespace | The white space between markup in a mixed content model. |
| Text | The content of the text node. |
| Whitespace | The white space between markup. |
| XmlDeclaration | The content of the declaration. |
The following example reads an XML file and displays each of the nodes.
reader.MoveToContent(); // Parse the file and display each of the nodes. while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: Console.Write("<{0}>", reader.Name); break; case XmlNodeType.Text: Console.Write(reader.Value); break; case XmlNodeType.CDATA: Console.Write("<![CDATA[{0}]]>", reader.Value); break; case XmlNodeType.ProcessingInstruction: Console.Write("<?{0} {1}?>", reader.Name, reader.Value); break; case XmlNodeType.Comment: Console.Write("<!--{0}-->", reader.Value); break; case XmlNodeType.XmlDeclaration: Console.Write("<?xml version='1.0'?>"); break; case XmlNodeType.Document: break; case XmlNodeType.DocumentType: Console.Write("<!DOCTYPE {0} [{1}]", reader.Name, reader.Value); break; case XmlNodeType.EntityReference: Console.Write(reader.Name); break; case XmlNodeType.EndElement: Console.Write("</{0}>", reader.Name); break; } }
The sample uses the items.xml file.
<?xml version="1.0"?> <!-- This is a sample XML document --> <!DOCTYPE Items [<!ENTITY number "123">]> <Items> <Item>Test with an entity: &number;</Item> <Item>Test with a child element <more/> stuff</Item> <Item>Test with a CDATA section <![CDATA[<456>]]> def</Item> <Item>Test with a char entity: A</Item> <!-- Fourteen chars in this element.--> <Item>1234567890ABCD</Item> </Items>
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Reference
XmlReader ClassXmlReader Members
System.Xml Namespace