private void ParseRecursive(IFormattedElement baseElement, HtmlNode baseNode) { foreach (var childNode in baseNode.ChildNodes) { IFormattedElement createdNode = null; switch (childNode.Name) { case "p": createdNode = new ParagraphFormattedElement(); break; case "b": case "strong": createdNode = new BoldFormattedElement(); break; case "i": case "em": createdNode = new ItalicFormattedElement(); break; case "ul": createdNode = new UnorderedListFormattedElement(); break; case "ol": createdNode = new OrderedListFormattedElement(); break; case "li": createdNode = new ListItemFormattedElement(); break; case "table": createdNode = new TableFormattedElement(); ExtractStyleWidth(childNode, (IWidthSpecifier)createdNode); break; case "tbody": case "thead": // ignore break; case "tr": createdNode = new TableRowFormattedElement(); break; case "td": case "th": createdNode = new TableCellFormattedElement(); ExtractStyleWidth(childNode, (IWidthSpecifier)createdNode); ExtractRowspanAndColspan(childNode, (TableCellFormattedElement)createdNode); break; case "img": createdNode = new ImageFormattedElement(); ExtractImageSource(childNode, (ImageFormattedElement)createdNode); ExtractStyleWidth(childNode, (IWidthSpecifier)createdNode); ExtractStyleHeight(childNode, (IHeightSpecifier)createdNode); break; default: createdNode = new TextFormattedElement(TrimText(HttpUtility.HtmlDecode(childNode.InnerText))); break; } if (createdNode != null) { baseElement.Children.Add(createdNode); createdNode.Parent = baseElement; ParseRecursive(createdNode, childNode); } else { // if element was skipped (e.g. tbody) ParseRecursive(baseElement, childNode); } } }
public override object Clone() { var clone = new UnorderedListFormattedElement(); clone.DeepCopyChildren(Children); return clone; }