XMLDocument & # 8594; Byte [] ... how to return to XMLDocument?

I have an XmlDocument and get the bytes of the object as follows:

XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("C:\\myxml.xml"); byte[] data = Encoding.UTF8.GetBytes(xmlDocument.outerXml); 

and the data is stored in a database.

Now I am reading the byte [] data and returning to the XmlDocument object. How can I do this since I cannot just pass byte [] to an XmlDocument?

Thanks.

+6
source share
1 answer

You can use the LoadXml method:

 byte[] data = ... fetch from your db string xml = Encoding.UTF8.GetString(data); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); // TODO: do something with the resulting XmlDocument 

UPDATE:

As stated in the comments section here, how to load an array of bytes into a DataTable :

 byte[] data = ... fetch from your db DataTable dt = ... fetch from somewhere or instantiate a new; using (var stream = new MemoryStream(data)) { dt.ReadXml(stream); } 
+10
source

Source: https://habr.com/ru/post/892267/


All Articles