Link to home
Start Free TrialLog in
Avatar of ZURINET
ZURINET

asked on

Loading byte data to an Xml Document

Dear all
Give the class below

I need a way to extract the Data from the DownloadFile class
and assign it or load the data to an xml document. See the code below for details

Somehow I need to achive this

using (MemoryStream baseMemStream = new MemoryStream(newDownLoadFile.[k].data))
                        {
                              xmlDoc.Load(baseMemStream);
                        }

Thanks in Advance
public class DownloadFile 
{ 
	public byte[] Data; 
	public String Filename; 
} 

DownloadFile[] newDownLoadFile = GetMyProtocol( String customerID, DateTime CreateDate,boolean SavedData );

Until now I have tried to assign the data to an xml document
XmlDocument myXmlDoc = new XmlDocument();
if (newDownLoadFile.Length > 0)
	{
	for (int k = 0; k < newDownLoadFile.Length; k++)
	myXmlDoc.load = newDownLoadFile[k].Data); // this is not working I need a stream
	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jagrut_patel
jagrut_patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZURINET
ZURINET

ASKER

Hi jagrut

Thanks for the feeback..
Tried it ... getting some erros..  (Root element is missing.)

Any Ideas..  Notwitstanding that I can use the code below to write it to file.. but need to a method that will retrun xml document..

 ByteArrayToFile(pathNew + varIncrement, newDownLoadFile[k].Data);
public void  ByteArrayToFile
// Open file for reading
				System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);

				
				// Writes a block of bytes to this stream using data from a byte array.
				_FileStream.Write(_ByteArray, 0, _ByteArray.Length);

				// close file stream
				_FileStream.Close();

Open in new window

The error suggest that XML data that you get in byte array is not XML compliant.
BTW, at which line of code you get this error?

Avatar of ZURINET

ASKER

Sorry solved it with another solution