XmlReader.Value Właściwość
Definicja
Gdy jest zastępowany w klasie pochodnej, pobiera wartość tekstową bieżącego węzła.When overridden in a derived class, gets the text value of the current node.
public:
abstract property System::String ^ Value { System::String ^ get(); };
public abstract string Value { get; }
member this.Value : string
Public MustOverride ReadOnly Property Value As String
Wartość właściwości
Zwracana wartość zależy od NodeType węzła.The value returned depends on the NodeType of the node. Poniższa tabela zawiera listę typów węzłów, które mają wartość zwracaną.The following table lists node types that have a value to return. Wszystkie inne typy węzłów zwracają String.Empty
.All other node types return String.Empty
.
Typ węzłaNode type | WartośćValue |
---|---|
Attribute | Wartość atrybutu.The value of the attribute. |
CDATA | Zawartość sekcji CDATA.The content of the CDATA section. |
Comment | Zawartość komentarza.The content of the comment. |
DocumentType | Podzestaw wewnętrzny.The internal subset. |
ProcessingInstruction | Cała zawartość, z wyłączeniem celu.The entire content, excluding the target. |
SignificantWhitespace | Odstęp między adiustacją w modelu zawartości mieszanej.The white space between markup in a mixed content model. |
Text | Zawartość węzła tekstowego.The content of the text node. |
Whitespace | Odstęp między znakami.The white space between markup. |
XmlDeclaration | Zawartość deklaracji.The content of the declaration. |
Wyjątki
Metoda XmlReader została wywołana przed ukończeniem poprzedniej operacji asynchronicznej.An XmlReader method was called before a previous asynchronous operation finished. W takim przypadku InvalidOperationException jest generowany z komunikatem "asynchroniczna operacja jest już w toku".In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."
Przykłady
Poniższy przykład odczytuje plik XML i wyświetla wszystkie węzły.The following example reads an XML file and displays each of the nodes.
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Parse;
XmlReader reader = XmlReader.Create("items.xml", settings);
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;
}
}
Dim settings As New XmlReaderSettings()
settings.DtdProcessing = DtdProcessing.Parse
Dim reader As XmlReader = XmlReader.Create("items.xml", settings)
reader.MoveToContent()
' Parse the file and display each of the nodes.
While reader.Read()
Select Case reader.NodeType
Case XmlNodeType.Element
Console.Write("<{0}>", reader.Name)
Case XmlNodeType.Text
Console.Write(reader.Value)
Case XmlNodeType.CDATA
Console.Write("<![CDATA[{0}]]>", reader.Value)
Case XmlNodeType.ProcessingInstruction
Console.Write("<?{0} {1}?>", reader.Name, reader.Value)
Case XmlNodeType.Comment
Console.Write("<!--{0}-->", reader.Value)
Case XmlNodeType.XmlDeclaration
Console.Write("<?xml version='1.0'?>")
Case XmlNodeType.Document
Case XmlNodeType.DocumentType
Console.Write("<!DOCTYPE {0} [{1}]", reader.Name, reader.Value)
Case XmlNodeType.EntityReference
Console.Write(reader.Name)
Case XmlNodeType.EndElement
Console.Write("</{0}>", reader.Name)
End Select
End While
Przykład używa pliku items.xml
.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>
Uwagi
W przypadku wersji asynchronicznej tej właściwości Zobacz metodę GetValueAsync.For the asynchronous version of this property, see the GetValueAsync method.