Decodes Base64 and returns the decoded binary bytes. : XmlTextReader « XML « C# / C Sharp

Decodes Base64 and returns the decoded binary bytes.


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;

        while (reader.Read()) {
           if ("Base64" == reader.Name) break;
        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");
        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("Processing of the file {0} complete.", filename);
        if (reader != null)


Related examples in the same category

1.Create XmlTextReader with the specified string, XmlNodeType, and XmlParserContext.
2.Initializes a new instance of the XmlTextReader class with the specified file.
3.Create XmlTextReader with TextReader.
4.Gets the number of attributes on the current node.
5.Gets the base URI of the current node.
6.Gets the depth of the current node in the XML document.
7.Gets the value of the attribute with the specified name.
8.Gets a value indicating whether the current node can have a Value other than String.Empty.
9.Gets a value indicating whether the current node is an empty element (for example, ).
10.Gets the current line position.
11.Gets the local name of the current node.
12.Moves to the first attribute.
13.Moves to the next attribute.
14.Gets the qualified name of the current node.
15.Gets or sets a value indicating whether to normalize white space and attribute values.
16.Parses the attribute value into one or more Text, EntityReference, or EndEntity nodes.
17.Reads the text contents of an element into a character buffer.
18.Resets the state of the reader to ReadState.Initial.
19.Gets or sets a value that specifies how white space is handled.
20.Gets the current xml:lang scope.
21.Sets the XmlResolver used for resolving DTD references.
22.Gets the current xml:space scope.