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

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

XmlValidatingReader.ReadAttributeValue メソッド

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

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

Public Overrides Function
 ReadAttributeValue As Boolean
Dim instance As XmlValidatingReader
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返します

解説解説

MoveToAttribute を呼び出した後、このメソッド使用して属性値構成するテキスト ノードまたはエンティティ参照ノード読み取ります。属性値ノードDepth は、属性ノード深さに 1 を加えた値です。一般エンティティ参照出入りするとき、Depthそれぞれ 1 つずつ増減します。

たとえば、次の XML <test name="a &b; c"/> があるとします

ここで、エンティティ b は、ドキュメント型定義 (DTD) で <!ENTITY b "123"> のように定義されます。

EntityHandling を ExpandCharEntities設定すると、次の C# コードは、属性値2 つテキスト ノード1 つエンティティ参照ノードとして返します

reader.MoveToAttribute("name");
  while (reader.ReadAttributeValue())
  {
  if (reader.NodeType == XmlNodeType.Text)
  {
  // at this point reader.Value == "a " or " c"
  }
  else if (reader.NodeType == XmlNodeType.EntityReference)
  {
  // at this point reader.Name == "b"
  reader.ResolveEntity();
  while (reader.ReadAttributeValue() &&
  reader.NodeType != XmlNodeType.EndEntity)
  {
  // reader.Value == "123"
  }
  }
    }
使用例使用例

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

Option Strict
Option Explicit

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim reader As XmlValidatingReader =
 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 and set it to not expand general entities.
 
            reader = New XmlValidatingReader(xmlFrag, XmlNodeType.Element,
 context)
            reader.ValidationType = ValidationType.None
            reader.EntityHandling = EntityHandling.ExpandCharEntities
            
            'Read the misc attribute. Because EntityHandling is set
 to
            'ExpandCharEntities, 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 'Main
End Class 'Sample 
using System;
using System.IO;
using System.Xml;

public class Sample 
{
  public static void Main()
  {
    XmlValidatingReader 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 and set it to not expand general entities.
 
       reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element,
 context);
       reader.ValidationType = ValidationType.None;
       reader.EntityHandling = EntityHandling.ExpandCharEntities;
  
       //Read the misc attribute. Because EntityHandling is set to
       //ExpandCharEntities, 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
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlValidatingReader^ 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 and set it to not expand general entities.
 
      reader = gcnew XmlValidatingReader( xmlFrag,XmlNodeType::Element,context );
      reader->ValidationType = ValidationType::None;
      reader->EntityHandling = EntityHandling::ExpandCharEntities;
      
      //Read the misc attribute. Because EntityHandling is set to
      //ExpandCharEntities, 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();
   }

}

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

public class Sample
{   
    public static void main(String[]
 args)
    {
        XmlValidatingReader 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 and set it to not expand general entities.
 
            reader = new XmlValidatingReader
                (xmlFrag, XmlNodeType.Element, context);
            reader.set_ValidationType(ValidationType.None);
            reader.set_EntityHandling(EntityHandling.ExpandCharEntities);

            //Read the misc attribute. Because EntityHandling is set
 to
            //ExpandCharEntities, 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)) {
                    //To expand the entity, call ResolveEntity.
                    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 クラス ライブラリ リファレンス」からXmlValidatingReader.ReadAttributeValue メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlValidatingReader.ReadAttributeValue メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlValidatingReader.ReadAttributeValue メソッド を検索

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS