XmlReader.ReadElementContentAsBinHex メソッド
アセンブリ: System.Xml (system.xml.dll 内)

Public Overridable Function ReadElementContentAsBinHex ( _ buffer As Byte(), _ index As Integer, _ count As Integer _ ) As Integer
Dim instance As XmlReader Dim buffer As Byte() Dim index As Integer Dim count As Integer Dim returnValue As Integer returnValue = instance.ReadElementContentAsBinHex(buffer, index, count)
public: virtual int ReadElementContentAsBinHex ( array<unsigned char>^ buffer, int index, int count )
戻り値
バッファに書き込まれたバイト数。


このメソッドは、要素のコンテンツを読み取り、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(); } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- XmlReader.ReadElementContentAsBinHex メソッドのページへのリンク