Assembly: System.Xml (in system.xml.dll)
Public Function ReadBinHex ( _ array As Byte(), _ offset As Integer, _ len As Integer _ ) As Integer
Dim instance As XmlTextReader Dim array As Byte() Dim offset As Integer Dim len As Integer Dim returnValue As Integer returnValue = instance.ReadBinHex(array, offset, len)
public int ReadBinHex ( byte[] array, int offset, int len )
public: int ReadBinHex ( array<unsigned char>^ array, int offset, int len )
public int ReadBinHex ( byte[] array, int offset, int len )
public function ReadBinHex ( array : byte[], offset : int, len : int ) : int
Parametri
- array
-
Matrice di byte che agisce da buffer in cui vengono scritti i byte binari decodificati.
- offset
-
Indice con base zero nella matrice che specifica il punto in cui il metodo può iniziare la scrittura nel buffer.
- len
-
Numero di byte da scrivere nel buffer.
Valore restituito
Numero di byte scritti nel buffer utente.| Tipo di eccezione | Condizione |
|---|---|
| La sequenza BinHex non è valida. |
|
| Il valore di array è riferimento null (Nothing in Visual Basic). |
|
| offset < 0 oppure len < 0 oppure len > array.Length-offset. |
Nota |
|---|
| Nella versione Microsoft .NET Framework versione 2.0 è consigliabile creare istanze di XmlReader utilizzando il metodo System.Xml.XmlReader.Create. In questo modo è possibile sfruttare completamente le nuove funzionalità introdotte in questa versione. Per ulteriori informazioni, vedere Creazione di lettori XML. |
In modo simile al metodo ReadChars, questo metodo può essere chiamato successivamente per consentire la lettura di flussi elevati di testo incorporato. Il metodo decodifica il contenuto BinHex e restituisce nel buffer i byte binari decodificati, ad esempio un'immagine GIF codificata BinHex inline.
Nell'esempio riportato di seguito viene letto un file contenente dati Base64 e BinHex.
Option Explicit Option Strict Imports System Imports System.IO Imports System.Xml Imports Microsoft.VisualBasic Public Class Sample Private Const filename As String = "binary.xml" Public Shared Sub Main() Dim reader As XmlTextReader = Nothing Dim i As Integer Try reader = New XmlTextReader(filename) reader.WhitespaceHandling = WhitespaceHandling.None ' Read the file. Stop at the Base64 element. While reader.Read() If "Base64" = reader.Name Then Exit While End If End While ' Read the Base64 data. Write the decoded ' bytes to the console. Console.WriteLine("Reading base64... ") Dim base64len As Integer = 0 Dim base64(1000) As Byte Do base64len = reader.ReadBase64(base64, 0, 50) For i = 0 To base64len - 1 Console.Write(base64(i)) Next i Loop While (reader.Name = "Base64") ' Read the BinHex data. Write the decoded ' bytes to the console. Console.WriteLine(ControlChars.CrLf & "Reading binhex....") Dim binhexlen As Integer = 0 Dim binhex(1000) As Byte binhexlen = reader.ReadBinHex(binhex, 0, 50) Do binhexlen = reader.ReadBinHex(binhex, 0, 50) For i = 0 To binhexlen - 1 Console.Write(binhex(i)) Next i Loop While (reader.Name = "BinHex") Finally Console.WriteLine() Console.WriteLine("Processing of the file {0} complete.", filename) 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 { private const string filename = "binary.xml"; public static void Main() { XmlTextReader reader = null; try { reader = new XmlTextReader(filename); reader.WhitespaceHandling = WhitespaceHandling.None; // Read the file. Stop at the Base64 element. while (reader.Read()) { if ("Base64" == reader.Name) break; } // Read the Base64 data. Write the decoded // bytes to the console. Console.WriteLine("Reading Base64... "); int base64len = 0; byte[] base64 = new byte[1000]; do { base64len = reader.ReadBase64(base64, 0, 50); for (int i=0; i < base64len; i++) Console.Write(base64[i]); } while (reader.Name == "Base64"); // Read the BinHex data. Write the decoded // bytes to the console. Console.WriteLine("\r\nReading BinHex..."); int binhexlen = 0; byte[] binhex = new byte[1000]; do { binhexlen = reader.ReadBinHex(binhex, 0, 50); for (int i=0; i < binhexlen; i++) Console.Write(binhex[i]); } while (reader.Name == "BinHex"); } finally { Console.WriteLine(); Console.WriteLine("Processing of the file {0} complete.", filename); if (reader != null) reader.Close(); } } }
#using <System.Xml.dll> using namespace System; using namespace System::IO; using namespace System::Xml; int main() { XmlTextReader^ reader = nullptr; String^ filename = "binary.xml"; try { reader = gcnew XmlTextReader( filename ); reader->WhitespaceHandling = WhitespaceHandling::None; // Read the file. Stop at the Base64 element. while ( reader->Read() ) { if ( "Base64" == reader->Name ) break; } // Read the Base64 data. Write the decoded // bytes to the console. Console::WriteLine( "Reading Base64... " ); int base64len = 0; array<Byte>^base64 = gcnew array<Byte>(1000); do { base64len = reader->ReadBase64( base64, 0, 50 ); for ( int i = 0; i < base64len; i++ ) Console::Write( base64[ i ] ); } while ( reader->Name->Equals( "Base64" ) ); // Read the BinHex data. Write the decoded // bytes to the console. Console::WriteLine( "\r\nReading BinHex..." ); int binhexlen = 0; array<Byte>^binhex = gcnew array<Byte>(1000); do { binhexlen = reader->ReadBinHex( binhex, 0, 50 ); for ( int i = 0; i < binhexlen; i++ ) Console::Write( binhex[ i ] ); } while ( reader->Name->Equals( "BinHex" ) ); } finally { Console::WriteLine(); Console::WriteLine( "Processing of the file {0} complete.", filename ); if ( reader != nullptr ) reader->Close(); } }
import System.*;
import System.IO.*;
import System.Xml.*;
public class Sample
{
private static String fileName = "binary.xml";
public static void main(String[] args)
{
XmlTextReader reader = null;
try {
reader = new XmlTextReader(fileName);
reader.set_WhitespaceHandling(WhitespaceHandling.None);
// Read the file. Stop at the Base64 element.
while(reader.Read()) {
if ("Base64".Equals(reader.get_Name())) {
break;
}
}
// Read the Base64 data. Write the decoded
// bytes to the console.
Console.WriteLine("Reading Base64... ");
int base64len = 0;
ubyte base64[] = new ubyte[1000];
do {
base64len = reader.ReadBase64(base64, 0, 50);
for(int i=0; i < base64len; i++) {
Console.Write(base64.get_Item(i));
}
}while (reader.get_Name().Equals("Base64"));
// Read the BinHex data. Write the decoded
// bytes to the console.
Console.WriteLine("\r\nReading BinHex...");
int binhexlen = 0;
ubyte binhex[] = new ubyte[1000];
do {
binhexlen = reader.ReadBinHex(binhex, 0, 50);
for(int i=0; i < binhexlen; i++) {
Console.Write(binhex.get_Item( i));
}
}while (reader.get_Name().Equals("BinHex"));
}
finally {
Console.WriteLine();
Console.WriteLine("Processing of the file {0} complete.",
fileName);
if (reader != null) {
reader.Close();
}
}
} //main
} //Sample
Nell'esempio viene utilizzato il file binary.xml.
<data> <!-- sample data for base64 and binhex --> <Base64>AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS 4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFi Y2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlp eYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrL zM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w ==</Base64> <BinHex>000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E 1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F4041 42434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F6061626364 65666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F8081828384858687 88898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AA ABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCD CECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0 F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF</BinHex> </data>
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile per Pocket PC, Windows Mobile per Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.
.NET Framework
Supportato in: 2.0 1.1 1.0.NET Compact Framework
Supportato in: 2.0 1.0Riferimenti
Classe XmlTextReaderMembri XmlTextReader
Spazio dei nomi System.Xml
Nota