XmlTextReader.ReadAttributeValue メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlTextReader.ReadAttributeValue メソッドの意味・解説 

XmlTextReader.ReadAttributeValue メソッド

属性値解析して1 つ上の textEntityReferenceEndEntity の各ノード格納します

名前空間: System.Xml
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Overrides Function
 ReadAttributeValue As Boolean
Dim instance As XmlTextReader
Dim returnValue As Boolean

returnValue = instance.ReadAttributeValue
public override bool ReadAttributeValue ()
public:
virtual bool ReadAttributeValue () override
public boolean ReadAttributeValue ()
public override function ReadAttributeValue
 () : boolean

戻り値
返すノードがある場合true初め呼び出すときにリーダー位置属性ノード上にない場合、またはすべての属性値読み込まれている場合は、falsemisc="" などの空の属性は、値 String.Empty を持つ単一ノード一緒に true返します

解説解説
使用例使用例

テキスト ノードおよびエンティティ ノードを持つ属性読み取る例を次に示します

Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    Dim reader as XmlTextReader = nothing

    try
       'Create the XML fragment to be parsed.
       Dim xmlFrag as string
 ="<book genre='novel' misc='sale-item &h; 1987'></book>"
 
       'Create the XmlParserContext.
       Dim context as XmlParserContext 
       Dim subset as string
 = "<!ENTITY h 'hardcover'>"
       context = new XmlParserContext(nothing,
 nothing, "book", nothing,
 nothing, subset, "", "", XmlSpace.None)
        
       'Create the reader.
       reader = new XmlTextReader(xmlFrag, XmlNodeType.Element,
 context)
  
       '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)
            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
        reader.Close()
      End if
      end try
  end sub
end class 
using System;
using System.IO;
using System.Xml;

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

    try
    {
       //Create the XML fragment to be parsed.
       string xmlFrag ="<book genre='novel' misc='sale-item
 &h; 1987'></book>";
 
       //Create the XmlParserContext.
       XmlParserContext context;
       string subset = "<!ENTITY h 'hardcover'>";
       context = new XmlParserContext(null,
 null, "book", null, null,
 subset, "", "", XmlSpace.None);
        
       //Create the reader.
       reader = new XmlTextReader(xmlFrag, XmlNodeType.Element,
 context);
  
       //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)
            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
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlTextReader^ reader = nullptr;
   __try
   {
      
      // Create the XML fragment to be parsed.
      String^ xmlFrag = "<book genre='novel' misc='sale-item &h; 1987'></book>";
      
      // Create the XmlParserContext.
      XmlParserContext^ context;
      String^ subset = "<!ENTITY h 'hardcover'>";
      context = gcnew XmlParserContext( nullptr,nullptr,"book",nullptr,nullptr,subset,"","",XmlSpace::None
 );
      
      // Create the reader.
      reader = gcnew XmlTextReader( xmlFrag,XmlNodeType::Element,context );
      
      // 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
 )
                  Console::WriteLine( " {0} {1}", reader->NodeType,
 reader->Name );
         else
                  Console::WriteLine( " {0} {1}", reader->NodeType,
 reader->Value );
      }
   }
   __finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}

import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[]
 args)
    {
        XmlTextReader reader = null;

        try {
            //Create the XML fragment to be parsed.
            String xmlFrag = "<book genre='novel' misc='sale-item &h;
 1987'>" 
                + "</book>";
            //Create the XmlParserContext.
            XmlParserContext context;
            String subset = "<!ENTITY h 'hardcover'>";
            context = new XmlParserContext(null,
 null, "book", null, null,
 
                subset, "", "", XmlSpace.None);
            //Create the reader.
            reader = new XmlTextReader(xmlFrag, XmlNodeType.Element,
 context);
            //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.get_NodeType().Equals(XmlNodeType.EntityReference))
 {
                    Console.WriteLine("{0} {1}", reader.get_NodeType()
,
 reader.
                    get_Name());
                }
                else {
                    Console.WriteLine("{0} {1}", reader.get_NodeType()
,
                        reader.get_Value());
                }
            }
        }
        finally {
            if (reader != null) {
                reader.Close();
            }
        }
    } //main
} //End class Sample 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からXmlTextReader.ReadAttributeValue メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlTextReader.ReadAttributeValue メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlTextReader.ReadAttributeValue メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

XmlTextReader.ReadAttributeValue メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlTextReader.ReadAttributeValue メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS