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

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

XmlReader.ReadElementContentAsBase64 メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

要素を読み取り、Base64 のコンテンツをデコードします。

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

Public Overridable Function
 ReadElementContentAsBase64 ( _
    buffer As Byte(), _
    index As Integer, _
    count As Integer _
) As Integer
public virtual int ReadElementContentAsBase64
 (
    byte[] buffer,
    int index,
    int count
)
public:
virtual int ReadElementContentAsBase64 (
    array<unsigned char>^ buffer, 
    int index, 
    int count
)
public int ReadElementContentAsBase64 (
    byte[] buffer, 
    int index, 
    int count
)
public function ReadElementContentAsBase64
 (
    buffer : byte[], 
    index : int, 
    count : int
) : int

パラメータ

buffer

結果として得られるテキストのコピー先のバッファ。この値を null 参照 (Visual Basic では Nothing) にすることはできません。

index

バッファ内の結果のコピー開始位置を示すオフセット。

count

バッファにコピーする最大バイト数。コピーされた実際のバイト数は、このメソッドから返されます。

戻り値
バッファに書き込まれたバイト数。

例外例外
例外の種類条件

ArgumentNullException

buffer 値が null 参照 (Visual Basic では Nothing) です。

InvalidOperationException

現在のノードは要素ノードではありません。

ArgumentOutOfRangeException

バッファ内のインデックス、またはインデックスとカウントの合計値が、割り当てられているバッファ サイズを超えています。

NotSupportedException

XmlReader 実装が、このメソッドをサポートしていません。

XmlException

要素には混合コンテンツが含まれます。

FormatException

コンテンツを要求された型に変換できません。

解説解説

このメソッドは、要素のコンテンツを読み取り、Base64 エンコーディングを使用してコンテンツをデコードしてから、デコードされたバイナリ バイト (Base64 でエンコードされたインライン GIF イメージなど) をバッファに返します。詳細については、RFC 1521『MIME (Multipurpose Internet Mail Exensions) Part One: Mechanisms for Specifying and Describing the Format of Internet Message Bodies』を参照してください。RFC は、http://www.rfc-editor.org にある Request for Comments の Web サイトから取得できます。

ReadElementContentAsBase64 で読み取ることができるのは、単純なコンテンツを含む要素のみです。要素には、テキスト、空白、有意の空白、CDATA セクション、コメント、および処理命令を含めることができます。また、エンティティ参照を含めることもでき、含めた場合は自動的に展開されます。要素が子要素を持つことはできません。

このメソッドは ReadContentAsBase64 メソッドに非常に似ていますが、このメソッドを呼び出すことができるのは要素ノード型に対してのみです。

count 値がドキュメント内のバイト数よりも大きい、または同じである場合は、XmlReader はドキュメント内の残りのバイトをすべて読み取り、読み取ったバイト数を返します。次の XmlReader メソッド呼び出しはゼロを返して、EndElement の次のノードにリーダーを移動します。

要素のすべてのコンテンツが処理される前に Read を呼び出すと、リーダーは、最初のコンテンツが処理された後で Read メソッドが呼び出された場合のように動作することがあります。つまりリーダーは、末尾の要素に到達するまですべてのテキストを読み取ります。次に終了タグ ノードを読み取り、次のノードを読み取ってから、後続のノード上に自身を配置します。

使用例使用例

インライン Base64 でエンコードされたイメージを読み取る例を次に示します。Base64 データは、<image> 要素内に埋め込まれます。BinaryWriter は、新しいバイナリ データ ファイルを作成するために使用されます。

Public Shared Sub Base64DecodeImageFile()
 
    
    Dim buffer(999) As Byte
    Dim readBytes As Integer
 = 0
    
    Using reader As XmlReader = XmlReader.Create("output.xml")

            Dim outputFile As New
 FileStream("C:\artFiles\data\newImage.jpg", FileMode.OpenOrCreate,
 FileAccess.Write, FileShare.Write)
            ' Read to the image element.
            reader.ReadToFollowing("image")
            ' Read the Base64 data.
            Console.WriteLine(vbCr + vbLf + "Reading Base64...")
            Dim bw As New
 BinaryWriter(outputFile)
            readBytes = reader.ReadElementContentAsBase64(buffer, 0, 50)
            While (readBytes > 0)
                bw.Write(buffer, 0, readBytes)
                readBytes = reader.ReadElementContentAsBase64(buffer, 0, 50)
            End While
            outputFile.Close()
        
    End Using

End Sub 'Base64DecodeImageFile
public static void Base64DecodeImageFile()
 {

  byte[] buffer = new byte[1000];
  int readBytes = 0;

  using (XmlReader reader = XmlReader.Create("output.xml"))
 {
                       
        FileStream outputFile = new FileStream(@"C:\artFiles\data\newImage.jpg"
,
                    FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write);
        // Read to the image element.
        reader.ReadToFollowing("image");
        // Read the Base64 data.
        Console.WriteLine("\r\nReading Base64...");
        BinaryWriter bw = new BinaryWriter(outputFile);
        while ((readBytes = reader.ReadElementContentAsBase64(buffer,
 0, 50))>0) {
            bw.Write(buffer, 0, readBytes);
        }
        outputFile.Close();
  }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「XmlReader.ReadElementContentAsBase64 メソッド」の関連用語

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

   

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



XmlReader.ReadElementContentAsBase64 メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS