using System.Collections;
using System.Collections.Generic;
public static void Main()
@"<p>今天<img alt='' src='http://localhost/survey_branch/api/fileOperation/GetCkEditorImage?filePath=images/admin/1214668322.jpg' style='height:64px; width:50px' />天氣真好<img alt='' src='http://localhost/survey_branch/api/fileOperation/GetCkEditorImage?filePath=images/admin/1214668322.jpg' style='height:64px; width:50px' />呀,對吧</p>";
List<Tuple<string,string>> domStorage = new List<Tuple<string,string>>();
HtmlDocument dom = new HtmlDocument();
HtmlNodeCollection tagCluster = dom.DocumentNode.ChildNodes;
if (tagCluster.Count > 1)
foreach (HtmlNode monoTag in tagCluster)
TraversalDomContent(domStorage, monoTag);
TraversalDomContent(domStorage, tagCluster[0]);
private static void TraversalDomContent(List<Tuple<string,string>> container, HtmlNode rootNode)
if (!rootNode.HasChildNodes)
string nodeType = rootNode.Name;
string nodeInformation = string.Empty;
if ( nodeType.Equals("img") )
string imageSource = rootNode.GetAttributeValue("src", string.Empty);
nodeInformation = GetImageFileName(imageSource);
nodeInformation = rootNode.InnerText;
container.Add(Tuple.Create<string, string>(nodeType, nodeInformation));
HtmlNodeCollection childCluster = rootNode.ChildNodes;
foreach (HtmlNode monoChild in childCluster)
TraversalDomContent(container, monoChild);
private static string GetImageFileName(string hrefLink)
string[] linkSplit = hrefLink.Split('=');
string fileName = Path.GetFileName(linkSplit[1]);