XmlNodeReader.ReadAttributeValue メソッド

定義

属性値を解析して、1 つ以上の TextEntityReferenceEndEntity の各ノードに格納します。Parses the attribute value into one or more Text, EntityReference, or EndEntity nodes.

public:
 override bool ReadAttributeValue();
public override bool ReadAttributeValue ();
override this.ReadAttributeValue : unit -> bool
Public Overrides Function ReadAttributeValue () As Boolean

戻り値

Boolean

返すノードがある場合は truetrue if there are nodes to return.

初めて呼び出すときにリーダーの位置が属性ノード上にない場合、またはすべての属性値が読み込まれている場合は falsefalse if the reader is not positioned on an attribute node when the initial call is made or if all the attribute values have been read.

misc="" などの空の属性は、値 String.Empty を持つ単一のノードと一緒に true を返します。An empty attribute, such as, misc="", returns true with a single node with a value of String.Empty.

次の例では、テキストおよびエンティティ参照ノードを含む属性を読み取ります。The following example reads an attribute with text and entity reference nodes.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlNodeReader^ reader = nullptr;
   try
   {
      
      //Create and load an XML document.
      XmlDocument^ doc = gcnew XmlDocument;
      doc->LoadXml( "<!DOCTYPE book [<!ENTITY h 'harcover'>]>"
      "<book genre='novel' misc='sale-item &h; 1987'>"
      "</book>" );
      
      //Create the reader. 
      reader = gcnew XmlNodeReader( doc );
      
      //Read the misc attribute. The attribute is parsed into multiple 
      //text and entity reference nodes.
      reader->MoveToContent();
      reader->MoveToAttribute( "misc" );
      while ( reader->ReadAttributeValue() )
      {
         if ( reader->NodeType == XmlNodeType::EntityReference )
                  
         //To expand the entity, call ResolveEntity.
         Console::WriteLine( "{0} {1}", reader->NodeType, reader->Name );
         else
                  Console::WriteLine( "{0} {1}", reader->NodeType, reader->Value );
      }
   }
   finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}

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

public class Sample
{
  public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
       //Create and load an XML document.
       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<!DOCTYPE book [<!ENTITY h 'harcover'>]>" +
                   "<book genre='novel' misc='sale-item &h; 1987'>" +
                   "</book>");

       //Create the reader.
       reader = new XmlNodeReader(doc);

       //Read the misc attribute. The attribute is parsed into multiple
       //text and entity reference nodes.
       reader.MoveToContent();
       reader.MoveToAttribute("misc");
       while (reader.ReadAttributeValue()){
          if (reader.NodeType==XmlNodeType.EntityReference)
            //To expand the entity, call ResolveEntity.
            Console.WriteLine("{0} {1}", reader.NodeType, reader.Name);
          else
             Console.WriteLine("{0} {1}", reader.NodeType, reader.Value);
        }
     }
     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 XML document.
            Dim doc As New XmlDocument()
            doc.LoadXml("<!DOCTYPE book [<!ENTITY h 'harcover'>]>" & _
                        "<book genre='novel' misc='sale-item &h; 1987'>" & _
                        "</book>")
            
            'Create the reader. 
            reader = New XmlNodeReader(doc)
            
            'Read the misc attribute. The attribute is parsed into multiple 
            'text and entity reference nodes.
            reader.MoveToContent()
            reader.MoveToAttribute("misc")
            While reader.ReadAttributeValue()
                If reader.NodeType = XmlNodeType.EntityReference Then
                    'To expand the entity, call ResolveEntity.
                    Console.WriteLine("{0} {1}", reader.NodeType, reader.Name)
                Else
                    Console.WriteLine("{0} {1}", reader.NodeType, reader.Value)
                End If
            End While
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

注釈

注意

.NET Framework 2.0 では、 XmlReader クラスとメソッドを使用してインスタンスを作成することをお勧めし XmlReaderSettings Create ます。In the .NET Framework 2.0, the recommended practice is to create XmlReader instances using the XmlReaderSettings class and the Create method. これにより、.NET Framework で導入されたすべての新機能を最大限に活用することができます。This allows you to take full advantage of all the new features introduced in the .NET Framework. 詳細については、リファレンスページの「解説」を参照してください XmlReaderFor more information, see the Remarks section in the XmlReader reference page.

を呼び出した後、このメソッドを使用し MoveToAttribute て、属性値を構成するテキストまたはエンティティ参照ノードを読み取ることができます。Use this method after calling MoveToAttribute to read through the text or entity reference nodes that make up the attribute value. Depth[属性値] ノードのは、[属性] ノードの深さに1を加えたものです。このノードは、一般エンティティ参照に対してステップインまたはステップアウトするときに1つずつ増減します。The Depth of the attribute value nodes is one plus the depth of the attribute node; it increments and decrements by one when you step into and out of general entity references.

適用対象