XmlNodeReader.HasValue プロパティ

定義

現在のノードに Valueを含めることができるかどうかを示す値を取得します。

public:
 virtual property bool HasValue { bool get(); };
public override bool HasValue { get; }
member this.HasValue : bool
Public Overrides ReadOnly Property HasValue As Boolean

プロパティ値

true リーダーが現在配置されているノードに Valueがある場合は >。それ以外の場合は false

次の例では、値を持つすべてのノードの値を表示します。

using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {

    XmlNodeReader reader = null;

    try {

        // Create and load an XmlDocument.
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<?xml version='1.0' ?>" +
                    "<!DOCTYPE book [<!ENTITY h 'hardcover'>]>" +
                    "<book>" +
                    "<title>Pride And Prejudice</title>" +
                    "<misc>&h;</misc>" +
                    "</book>");

        reader = new XmlNodeReader(doc);

        // Parse the file and display each node.
        while (reader.Read()) {
           if (reader.HasValue)
             Console.WriteLine("({0})  {1}={2}", reader.NodeType, reader.Name, reader.Value);
           else
             Console.WriteLine("({0}) {1}", reader.NodeType, reader.Name);
         }
     }

     finally {
       if (reader!=null)
         reader.Close();
     }
  }
} // End class
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    Public Shared Sub Main()
        Dim reader As XmlNodeReader = Nothing
        
        Try
            'Create and load an XmlDocument.
            Dim doc As New XmlDocument()
            doc.LoadXml("<?xml version='1.0' ?>" & _
                        "<!DOCTYPE book [<!ENTITY h 'hardcover'>]>" & _
                        "<book>" & _
                        "<title>Pride And Prejudice</title>" & _
                        "<misc>&h;</misc>" & _
                        "</book>")
            
            reader = New XmlNodeReader(doc)
            
            'Parse the file and display each node.
            While reader.Read()
                If reader.HasValue Then
                    Console.WriteLine("({0})  {1}={2}", reader.NodeType, reader.Name, reader.Value)
                Else
                    Console.WriteLine("({0}) {1}", reader.NodeType, reader.Name)
                End If
            End While
        
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

注釈

Note

新しい機能を利用するには、XmlReader クラスと XmlReaderSettings メソッドを使用してCreate インスタンスを作成することをお勧めします。 詳細については、「 XmlReader リファレンス」ページの「解説」セクションを参照してください。

次の表に、返す値を持つノードの種類を示します。

ノード タイプ 価値
Attribute 属性の値。
CDATA CDATA セクションの内容。
Comment コメントの内容。
DocumentType 内部サブセット。
ProcessingInstruction ターゲットを除くコンテンツ全体。
SignificantWhitespace 混合コンテンツ モデル内のマークアップ間の空白。
Text テキスト ノードの内容。
Whitespace マークアップ間の空白。
XmlDeclaration 宣言の内容。

適用対象