XmlReader.ReadElementContentAsBinHex(Byte[], Int32, Int32) 메서드

정의

요소를 읽고 BinHex 콘텐츠를 디코딩합니다.

public:
 virtual int ReadElementContentAsBinHex(cli::array <System::Byte> ^ buffer, int index, int count);
public virtual int ReadElementContentAsBinHex (byte[] buffer, int index, int count);
abstract member ReadElementContentAsBinHex : byte[] * int * int -> int
override this.ReadElementContentAsBinHex : byte[] * int * int -> int
Public Overridable Function ReadElementContentAsBinHex (buffer As Byte(), index As Integer, count As Integer) As Integer

매개 변수

buffer
Byte[]

결과 텍스트를 복사해 넣을 버퍼입니다. 이 값은 null일 수 없습니다.

index
Int32

버퍼에 넣을 결과 복사가 시작되는 오프셋입니다.

count
Int32

버퍼에 복사할 최대 바이트 수입니다. 복사된 실제 바이트 수가 이 메서드에서 반환됩니다.

반환

Int32

버퍼에 쓴 바이트 수입니다.

예외

buffer 값이 null입니다.

현재 노드가 요소 노드가 아닌 경우

또는

이전 비동기 작업이 완료되기 전에 XmlReader 메서드가 호출되었습니다. 이 경우 “비동기 작업이 이미 진행 중입니다.” 메시지를 나타내며 InvalidOperationException이 throw됩니다.

버퍼 내의 인덱스 또는 인덱스와 개수를 합한 값이 할당된 버퍼 크기보다 큰 경우

구현된 XmlReader에서 이 메서드를 지원하지 않는 경우

요소가 혼합 콘텐츠를 포함하는 경우

요소를 요청한 형식으로 변환할 수 없는 경우

예제

다음 예제에서는 인라인 BinHex 으로 인코딩된 이미지를 읽습니다. 데이터는 BinHex 요소 내에 <image> 포함됩니다. A BinaryWriter 는 새 이진 데이터 파일을 만드는 데 사용됩니다.

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();
  }
}
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

설명

이 메서드는 요소 콘텐츠를 읽고, 인코딩을 사용하여 BinHex 디코딩하고, 디코딩된 이진 바이트(예: 인라인 BinHex인코딩된 GIF 이미지)를 버퍼에 반환합니다.

이 메서드는 단순 콘텐츠 요소만 읽을 수 있습니다. 요소에는 텍스트, 공백, 상당한 공백, CDATA 섹션, 주석 및 처리 지침이 포함될 수 있습니다. 자동으로 확장되는 엔터티 참조를 포함할 수도 있습니다. 요소에 자식 요소가 있을 수 없습니다.

이 메서드는 요소 노드 형식에서 ReadContentAsBinHex 만 호출할 수 있다는 점을 제외하고 메서드와 매우 유사합니다.

값이 count 문서의 바이트 수보다 크거나 문서의 바이트 수와 같으면 문서의 XmlReader 나머지 바이트를 모두 읽고 읽은 바이트 수를 반환합니다. 다음 XmlReader 메서드 호출은 0을 반환하고 판독기를 다음 EndElement노드로 이동합니다.

모든 요소 콘텐츠를 소비하기 전에 호출 Read 하는 경우 판독기는 첫 번째 콘텐츠가 사용된 후 메서드가 호출된 것처럼 동작할 Read 수 있습니다. 즉, 판독기는 끝 요소가 발견될 때까지 모든 텍스트를 읽습니다. 그런 다음, 끝 태그 노드를 읽고, 다음 노드를 읽은 다음, 다음 후속 노드에 배치합니다.

이 메서드의 비동기 버전은 다음을 참조하세요 ReadElementContentAsBinHexAsync.

적용 대상

추가 정보