XmlReader.Value Property
Microsoft Silverlight will reach end of support after October 2021. Learn more.
When overridden in a derived class, gets the text value of the current node.
Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Syntax
'Declaration
Public MustOverride ReadOnly Property Value As String
public abstract string Value { get; }
Property Value
Type: System.String
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. |
Examples
Dim output As New StringBuilder()
Dim xmlString As String = _
"<bookstore>" & _
"<book genre='novel' ISBN='10-861003-324'>" & _
"<title>The Handmaid's Tale</title>" & _
"<price>19.95</price>" & _
"</book>" & _
"<book genre='novel' ISBN='1-861001-57-5'>" & _
"<title>Pride And Prejudice</title>" & _
"<price>24.95</price>" & _
"</book>" & _
"</bookstore>"
' Load the file and ignore all white space.
Dim settings As New XmlReaderSettings()
settings.IgnoreWhitespace = True
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString), settings)
' Move the reader to the second book node.
reader.MoveToContent()
reader.ReadToDescendant("book")
reader.Skip() 'Skip the first book.
' Parse the file starting with the second book node.
Do
Select Case reader.NodeType
Case XmlNodeType.Element
output.AppendLine("<" + reader.Name)
While reader.MoveToNextAttribute()
output.AppendLine(" " + reader.Name + "=" + reader.Value)
End While
output.AppendLine(">")
Case XmlNodeType.Text
output.AppendLine(reader.Value)
Case XmlNodeType.EndElement
output.AppendLine("</" + reader.Name + ">")
End Select
Loop While reader.Read()
OutputTextBlock.Text = output.ToString()
End Using
StringBuilder output = new StringBuilder();
String xmlString =
@"<bookstore>
<book genre='novel' ISBN='10-861003-324'>
<title>The Handmaid's Tale</title>
<price>19.95</price>
</book>
<book genre='novel' ISBN='1-861001-57-5'>
<title>Pride And Prejudice</title>
<price>24.95</price>
</book>
</bookstore>";
// Load the file and ignore all white space.
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString), settings))
{
// Move the reader to the second book node.
reader.MoveToContent();
reader.ReadToDescendant("book");
reader.Skip(); //Skip the first book.
// Parse the file starting with the second book node.
do
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
output.AppendLine("<" + reader.Name);
while (reader.MoveToNextAttribute())
{
output.AppendLine(" " + reader.Name + "=" + reader.Value);
}
output.AppendLine(">");
break;
case XmlNodeType.Text:
output.AppendLine(reader.Value);
break;
case XmlNodeType.EndElement:
output.AppendLine("</" + reader.Name + ">");
break;
}
} while (reader.Read());
}
OutputTextBlock.Text = output.ToString();
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
XNA Framework
Supported in: Xbox 360, Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
See Also