How do I convert the xml in an XDocument to a MemoryStream?
+6
A:
Have a look at the XDocument.WriteTo method, e.g.
MemoryStream ms = new MemoryStream();
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Indent = true;
using (XmlWriter xw = XmlWriter.Create(ms, xws))
{
XDocument doc = new XDocument(
new XElement("Child",
new XElement("GrandChild", "some content")
)
);
doc.WriteTo(xw);
}
dtb
2009-04-15 03:56:12
Or .Save - but the example holds ;-p
Marc Gravell
2009-04-15 06:16:33
@Marc What's the difference between WriteTo() and Save()?
Daniel Fortunov
2010-03-01 15:11:31
@Daniel Fortunov: .Save provides more overloads, but all of these end up calling .WriteTo
dtb
2010-03-01 16:59:46
A:
VARIANT_BOOL bstatus; bool bRetVal = false; BSTR bstr;
wi_CharToBSTR(source , bstr);
// Load from Buffer
//
HRESULT hr = m_pXMLDomDoc->loadXML(bstr,&bstatus);
if (bstatus == VARIANT_TRUE)
{
// now that the document is loaded, initialize the root pointer
m_pXMLDomDoc->get_documentElement(&m_pXMLRoot);
bRetVal = true;
}
SysFreeString(bstr);
Chand
2009-04-15 04:05:06
-1: XDocument is LINQ to XML's API. You seem to be using MSXML, not even .NET or C#.
Richard
2009-04-15 10:04:04