开发者

C# XElement: Node Formatting with HTML

I'm extracting XML node from an XElement. When I use XElement.Value it strips any HTML that may be in the node.

I know that if I do XElement.ToString() I can keep the HTML, but it also gives me the node tags. Is there any way to extract the content of a Node as is witho开发者_如何学Cut the HTML being stripped out?

Cheers.


Alternatively:

using System.Xml.XPath;

string xml = node.CreateNavigator().InnerXml;


You need to concatenate the nodes inside the XElement, like this:

node.Nodes().Aggregate(new StringBuilder(), (sb, n) => sb.Append(n.ToString())).ToString()

Or, in .Net 4.0:

String.Concat(node.Nodes())
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜