在下面的代码中获取混合 body元素的内容的最佳方法是什么?元素可能包含 XHTML 或文本,但我只希望它的内容采用字符串形式。XmlElement类型具有 InnerXml属性,这正是我想要的。
编写的代码 差不多做我想做的事情,但是包含了周围的 <body>... </body>元素,这是我不想要的。
XDocument doc = XDocument.Load(new StreamReader(s));
var templates = from t in doc.Descendants("template")
where t.Attribute("name").Value == templateName
select new
{
Subject = t.Element("subject").Value,
Body = t.Element("body").ToString()
};