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()
};
Run Code Online (Sandbox Code Playgroud)