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

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

XmlReader.ReadElementContentAsBinHex メソッド

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

要素を読み取り、BinHex の内容をデコードします。

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

Public Overridable Function
 ReadElementContentAsBinHex ( _
    buffer As Byte(), _
    index As Integer, _
    count As Integer _
) As Integer
public virtual int ReadElementContentAsBinHex
 (
    byte[] buffer,
    int index,
    int count
)
public:
virtual int ReadElementContentAsBinHex (
    array<unsigned char>^ buffer, 
    int index, 
    int count
)
public int ReadElementContentAsBinHex (
    byte[] buffer, 
    int index, 
    int count
)
public function ReadElementContentAsBinHex
 (
    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

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

解説解説

このメソッドは、要素のコンテンツを読み取り、BinHex エンコーディングを使用してコンテンツをデコードしてから、デコードされたバイナリ バイト (BinHex でエンコードされたインライン GIF イメージなど) をバッファに返します。

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

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

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

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

使用例使用例

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

Public Shared Sub BinHexDecodeImageFile()
 
    
    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 BinHex data.
            Console.WriteLine(vbCr + vbLf + "Reading BinHex...")
            Dim bw As New
 BinaryWriter(outputFile)
            readBytes = reader.ReadElementContentAsBinHex(buffer, 0, 50)
            While (readBytes > 0)
                bw.Write(buffer, 0, readBytes)
                readBytes = reader.ReadElementContentAsBinHex(buffer, 0, 50)
            End While
            outputFile.Close()
        
    End Using

End Sub 'BinHexDecodeImageFile

public static void BinHexDecodeImageFile()
 {

  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 BinHex data.
        Console.WriteLine("\r\nReading BinHex...");
        BinaryWriter bw = new BinaryWriter(outputFile);
        while ((readBytes = reader.ReadElementContentAsBinHex(buffer,
 0, 50))>0) {
            bw.Write(buffer, 0, readBytes);
        }
        outputFile.Close();
        
  }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2026 GRAS Group, Inc.RSS