I have many posts (e.g. this one) on SO that explain how to write binary data in XML using the XMLWriter.WriteBase64 method. However, I have not yet seen one that explains how to read base64'd data. Is there any other built-in method? It is also difficult for me to find reliable documentation on this subject.
Here is the XML file I'm using:
<?xml version="1.0"?> <pstartdata> <pdata>some data here</pdata> emRyWVZMdFlRR0FFQUNoYUwzK2dRUGlBS1ZDTXdIREF ..... and much, much more. </pstartdata>
C # code that creates this file (.Net 4.0):
FileStream fs = new FileStream(Path.GetTempPath() + "file.xml", FileMode.Create); System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter(fs, null); w.Formatting = System.Xml.Formatting.None; w.WriteStartDocument(); w.WriteStartElement("pstartdata"); #region Main Data w.WriteElementString("pdata", "some data here");
Now, for the real task ... Good, since you all see that it was written in .Net 4.0. Unfortunately, the XML file must be read by the application using .Net 2.0. Reading in binary (base 64) data turned out to be a rather difficult task.
Code for reading in XML data (.Net 2.0):
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument(); xDoc.LoadXml(xml_data); foreach (System.Xml.XmlNode node in xDoc.SelectNodes("pstartdata")) { foreach (System.Xml.XmlNode child in node.ChildNodes) { MessageBox.Show(child.InnerXml); } }
What needs to be added for reading in basic 64 data (shown above)?
user725913
source share