This project has moved and is read-only. For the latest updates, please go here.

Save output to XML and load to XML document

Topics: User Forum
Jan 5, 2007 at 4:13 PM

I am trying to save the HTML document as XML and have it loaded into an XMLdocument for manipulation. I have saved the document to a memory stream and am trying to load that to an XML document but it does not work. Something about and unclosed literal. If I save the document to an xml file and then load it it works fine.

Here is what I have.
MemoryStream myStream = new MemoryStream();
HtmlDocument doc = new HtmlDocument();
doc.OptionOutputAsXml = true;
doc.OptionOutputOptimizeAttributeValues = true;
// doc.Save(myStream);
MemoryStream loadStream = new MemoryStream();
XmlDocument myXML = new XmlDocument();
byte[] byteArray = myStream.ToArray();
loadStream.Write(byteArray, 0, byteArray.Length);
loadStream.Position = 0;


Dec 29, 2007 at 6:15 AM
This seemed to work for me:

public static XmlDocument getXmlDoc(String HTML)

HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.OptionOutputAsXml = true;

System.IO.MemoryStream stream = new System.IO.MemoryStream();

XmlTextWriter xtw = new XmlTextWriter(stream, null);
// Load the content into the writer


// Rewind the memory stream
stream.Position = 0;

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml((new System.IO.StreamReader(stream)).ReadToEnd());
return xmlDoc;

Jan 15, 2008 at 2:31 PM
Dear daximus:
Would it be possible to help me how to make your program work?
And I am not sure the code of "htmlDoc.LoadHtml(HTML)" .Do it can load specific file of html?
Thank you for your kindly help.