Alex Rivera | Logout

How to get Xml as string from XDocument?

Asked 2010-12-26T11:07:31.457
90

I am new to LINQ to XML. After you have built XDocument, how do you get the OuterXml of it like you did with XmlDocument?

Edit
Report

1 Answer

2

Use ToString() to convert XDocument into a string:

string result = string.Empty;
XElement root = new XElement("xml",
    new XElement("MsgType", "<![CDATA[" + "text" + "]]>"),
    new XElement("Content", "<![CDATA[" + "Hi, this is Wilson Wu Testing for you! You can ask any question but no answer can be replied...." + "]]>"),
    new XElement("FuncFlag", 0)
);
result = root.ToString();
answered 2013-04-12T09:45:21.903

Your Answer