3using System.Globalization;
16 private readonly
string htmlText;
19 private Title title =
null;
20 private Body body =
null;
21 private Head head =
null;
63 private void AssertParsed()
65 if (this.root is
null)
264 public IEnumerable<Nav>
Nav
312 public IEnumerable<Elements.Audio>
Audio
324 public IEnumerable<Elements.Video>
Video
336 public IEnumerable<Img>
Img
396 public IEnumerable<Elements.Script>
Script
420 public IEnumerable<DtdInstruction>
Dtd
437 return this.processingInstructions;
443 StringBuilder sb =
new StringBuilder();
447 string Name =
string.Empty;
450 char EndChar =
'\x00';
453 int StartOfElement = 0;
455 int StartOfAttribute = 0;
456 int Len = this.htmlText.Length;
458 bool CurrentElementIsScript =
false;
460 for (Pos = 0; Pos < Len; Pos++)
462 ch = this.htmlText[Pos];
472 CurrentElement = CurrentElement.Parent as
HtmlElement;
474 CurrentElement?.Add(
new HtmlText(
this, CurrentElement, StartOfText, Pos - 1, sb.ToString()));
480 StartOfElement = Pos;
488 CurrentElement = CurrentElement.Parent as
HtmlElement;
490 CurrentElement?.Add(
new HtmlText(
this, CurrentElement, StartOfText, Pos - 1, sb.ToString()));
510 else if (CurrentElementIsScript)
514 StartOfText = Pos + 1 - sb.Length;
520 else if (ch ==
'!' && Empty)
522 else if (CurrentElementIsScript)
526 StartOfText = Pos + 1 - sb.Length;
535 StartOfText = Pos + 1 - sb.Length;
540 CurrentElement = this.CreateElement(CurrentElement, sb.ToString(), StartOfElement, Pos);
541 CurrentElementIsScript = CurrentElement is Elements.Script;
546 StartOfText = Pos + 1;
550 else if (ch <=
' ' || ch == 160)
557 StartOfText = Pos + 1 - sb.Length;
560 else if (CurrentElementIsScript)
564 StartOfText = Pos + 1 - sb.Length;
569 CurrentElement = this.CreateElement(CurrentElement, sb.ToString(), StartOfElement, Pos);
570 CurrentElementIsScript = CurrentElement is Elements.Script;
580 else if (IsNameCharacter(ch))
590 StartOfText = Pos + 1 - sb.Length;
598 else if (CurrentElementIsScript)
603 StartOfText = Pos + 1 - sb.Length;
608 if (this.dtd is
null)
614 CurrentElement = CurrentElement.Parent as
HtmlElement;
616 CurrentElement?.Add(
Dtd);
619 StartOfText = Pos + 1;
636 EmptyElement = this.CreateElement(CurrentElement, sb.ToString(), StartOfElement, Pos);
637 EmptyElement.EndPosition = Pos;
642 StartOfText = Pos + 1;
657 s = sb.ToString().ToUpper();
661 if (!(CurrentElement is
null))
664 CurrentElement.EndPosition = Pos;
668 CurrentElement = CurrentElement.Parent as
HtmlElement;
669 CurrentElementIsScript = CurrentElement is Elements.Script;
675 while (!(Loop is
null) && Loop.
FullName != s)
682 while (!(Loop is
null) && Loop.
FullName != s)
685 Loop.EndPosition = Pos;
691 Loop.EndPosition = Pos;
694 CurrentElementIsScript = CurrentElement is Elements.Script;
699 StartOfText = Pos + 1;
713 CurrentElement.EndPosition = Pos;
715 StartOfText = Pos + 1;
722 StartOfAttribute = Pos;
726 else if (ch >
' ' && ch != 160)
728 if (IsNameCharacter(ch))
730 StartOfAttribute = Pos;
748 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, sb.ToString(),
string.Empty));
753 StartOfText = Pos + 1;
758 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, sb.ToString(),
string.Empty));
767 Name = sb.ToString();
776 if (ch <=
' ' || ch == 160)
778 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, sb.ToString(),
string.Empty));
785 else if (IsNameCharacter(ch))
801 if (ch ==
'"' || ch ==
'\'')
803 CurrentAttribute =
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Name);
804 CurrentElement.AddAttribute(CurrentAttribute);
811 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, Name, Name));
812 StartOfText = Pos + 1;
817 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, Name, Name));
820 else if (ch >
' ' && ch != 160)
828 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, Name, Name));
838 if (ch <=
' ' || ch == 160)
840 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, Name, sb.ToString()));
849 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, Name, sb.ToString()));
854 StartOfText = Pos + 1;
859 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, Name, sb.ToString()));
876 CurrentElement.EndPosition = Pos;
877 CurrentElement = CurrentElement.Parent as
HtmlElement;
878 CurrentElementIsScript = CurrentElement is Elements.Script;
879 StartOfText = Pos + 1;
885 if ((ch >=
'a' && ch <=
'z') || (ch >=
'A' && ch <=
'Z') || (ch >=
'0' && ch <=
'9'))
898 StartOfText = Pos + 1 - sb.Length;
910 if (CurrentAttribute.HasSegments)
911 CurrentAttribute.Add(
new HtmlText(
this, CurrentAttribute, Pos - s.Length, Pos - 1, s));
913 CurrentAttribute.Value = s;
915 CurrentAttribute.EndPosition = Pos;
929 CurrentAttribute.Add(
new HtmlText(
this, CurrentAttribute, Pos - s.Length, Pos - 1, s));
945 if ((ch >=
'a' && ch <=
'z') || (ch >=
'A' && ch <=
'Z') || (ch >=
'0' && ch <=
'9'))
965 StartOfText = Pos + 1;
975 if (this.dtd is
null)
982 CurrentElement = CurrentElement.Parent as
HtmlElement;
984 CurrentElement?.Add(
Dtd);
990 StartOfText = Pos + 1;
1009 StartOfText = Pos + 1 - sb.Length;
1041 CurrentElement = CurrentElement.Parent as
HtmlElement;
1044 CurrentElement?.Add(
new Comment(
this, CurrentElement, Pos - s.Length - 5, Pos, s));
1049 StartOfText = Pos + 1;
1080 if (this.processingInstructions is
null)
1087 CurrentElement = CurrentElement.Parent as
HtmlElement;
1089 CurrentElement?.Add(PI);
1090 this.processingInstructions.
Add(PI);
1095 StartOfText = Pos + 1;
1116 StartOfText = Pos + 1 - sb.Length;
1129 StartOfText = Pos + 1 - sb.Length;
1142 StartOfText = Pos + 1 - sb.Length;
1152 sb.Append(
"<![CDA");
1155 StartOfText = Pos + 1 - sb.Length;
1165 sb.Append(
"<![CDAT");
1168 StartOfText = Pos + 1 - sb.Length;
1178 sb.Append(
"<![CDATA");
1181 StartOfText = Pos + 1 - sb.Length;
1212 CurrentElement = CurrentElement.Parent as
HtmlElement;
1215 CurrentElement?.Add(
new CDATA(
this, CurrentElement, Pos - s.Length - 10, Pos, s));
1220 StartOfText = Pos + 1;
1233 if ((ch >=
'a' && ch <=
'z') || (ch >=
'A' && ch <=
'Z') || (ch >=
'0' && ch <=
'9'))
1238 CurrentElement = CurrentElement.Parent as
HtmlElement;
1241 CurrentElement?.Add(
new HtmlEntity(
this, CurrentElement, Pos - s.Length - 1, Pos, s));
1246 StartOfText = Pos + 1;
1254 StartOfText = Pos + 1 - sb.Length;
1260 if (ch >=
'0' && ch <=
'9')
1265 else if (ch ==
'x' || ch ==
'X')
1267 else if (ch ==
';' &&
int.TryParse(s = sb.ToString(), out
int Code))
1270 CurrentElement = CurrentElement.Parent as
HtmlElement;
1272 CurrentElement?.Add(
new HtmlEntityUnicode(
this, CurrentElement, Pos - s.Length - 1, Pos,
"#" + s,
Code));
1277 StartOfText = Pos + 1;
1285 StartOfText = Pos + 1 - sb.Length;
1291 if (ch >=
'0' && ch <=
'9')
1293 else if (ch ==
';' &&
int.TryParse(s = sb.ToString(), out
int Code))
1296 CurrentElement = CurrentElement.Parent as
HtmlElement;
1298 CurrentElement?.Add(
new HtmlEntityUnicode(
this, CurrentElement, Pos - s.Length - 1, Pos,
"#" + s,
Code));
1303 StartOfText = Pos + 1;
1311 StartOfText = Pos + 1 - sb.Length;
1317 if ((ch >=
'0' && ch <=
'9') || (ch >=
'a' && ch <=
'f') || (ch >=
'A' && ch <=
'F'))
1319 else if (ch ==
';' &&
int.TryParse(s = sb.ToString(), NumberStyles.HexNumber,
null, out
int Code))
1322 CurrentElement = CurrentElement.Parent as
HtmlElement;
1324 CurrentElement?.Add(
new HtmlEntityUnicode(
this, CurrentElement, Pos - s.Length - 1, Pos,
"#x" + s,
Code));
1329 StartOfText = Pos + 1;
1334 sb.Insert(0,
"&#x");
1337 StartOfText = Pos + 1 - sb.Length;
1343 if ((ch >=
'a' && ch <=
'z') || (ch >=
'A' && ch <=
'Z') || (ch >=
'0' && ch <=
'9'))
1348 CurrentAttribute.Add(
new HtmlEntity(
this, CurrentAttribute, Pos - s.Length - 1, Pos, s));
1353 StartOfText = Pos + 1;
1361 StartOfText = Pos + 1 - sb.Length;
1367 if (ch >=
'0' && ch <=
'9')
1372 else if (ch ==
'x' || ch ==
'X')
1374 else if (ch ==
';' &&
int.TryParse(s = sb.ToString(), out
int Code))
1376 CurrentAttribute.Add(
new HtmlEntityUnicode(
this, CurrentAttribute, Pos - s.Length - 1, Pos, s,
Code));
1381 StartOfText = Pos + 1;
1389 StartOfText = Pos + 1 - sb.Length;
1395 if (ch >=
'0' && ch <=
'9')
1397 else if (ch ==
';' &&
int.TryParse(s = sb.ToString(), out
int Code))
1399 CurrentAttribute.Add(
new HtmlEntityUnicode(
this, CurrentAttribute, Pos - s.Length - 1, Pos, s,
Code));
1404 StartOfText = Pos + 1;
1412 StartOfText = Pos + 1 - sb.Length;
1418 if ((ch >=
'0' && ch <=
'9') || (ch >=
'a' && ch <=
'f') || (ch >=
'A' && ch <=
'F'))
1420 else if (ch ==
';' &&
int.TryParse(s = sb.ToString(), NumberStyles.HexNumber,
null, out
int Code))
1422 CurrentAttribute.Add(
new HtmlEntityUnicode(
this, CurrentAttribute, Pos - s.Length - 1, Pos, s,
Code));
1427 StartOfText = Pos + 1;
1432 sb.Insert(0,
"&#x");
1435 StartOfText = Pos + 1 - sb.Length;
1441 throw new Exception(
"Internal error: Unrecognized state.");
1453 CurrentElement = CurrentElement.Parent as
HtmlElement;
1456 CurrentElement?.Add(
new HtmlText(
this, CurrentElement, Pos - s.Length, Pos - 1, s));
1461 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, s, s));
1465 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, Name, Name));
1469 CurrentElement.AddAttribute(
new HtmlAttribute(
this, CurrentElement, StartOfAttribute, Pos - 1, Name, sb.ToString()));
1475 CurrentElement = CurrentElement.Parent as
HtmlElement;
1479 CurrentElement?.Add(
new HtmlText(
this, CurrentElement, Pos - s.Length, Pos - 1, s));
1485 if (CurrentAttribute.HasSegments)
1486 CurrentAttribute.Add(
new HtmlText(
this, CurrentAttribute, Pos - s.Length, Pos - 1, s));
1488 CurrentAttribute.Value = s;
1490 CurrentAttribute.EndPosition = Pos - 1;
1497 CurrentAttribute.Add(
new HtmlText(
this, CurrentElement, Pos - s.Length, Pos - 1, s));
1504 CurrentElement = CurrentElement.Parent as
HtmlElement;
1507 CurrentElement?.Add(
new Comment(
this, CurrentElement, Pos - s.Length - 5, Pos, s));
1512 if (this.processingInstructions is
null)
1519 CurrentElement = CurrentElement.Parent as
HtmlElement;
1521 CurrentElement?.Add(PI);
1522 this.processingInstructions.
Add(PI);
1529 CurrentElement = CurrentElement.Parent as
HtmlElement;
1532 CurrentElement?.Add(
new CDATA(
this, CurrentElement, Pos - s.Length, Pos - 1, s));
1538 CurrentElement = CurrentElement.Parent as
HtmlElement;
1542 CurrentElement?.Add(
new HtmlText(
this, CurrentElement, Pos - s.Length, Pos - 1, s));
1547 CurrentElement = CurrentElement.Parent as
HtmlElement;
1549 sb.Insert(0,
"&#x");
1551 CurrentElement?.Add(
new HtmlText(
this, CurrentElement, Pos - s.Length, Pos - 1, s));
1559 CurrentAttribute.Add(
new HtmlText(
this, CurrentElement, Pos - s.Length, Pos - 1, s));
1563 sb.Insert(0,
"&#x");
1565 CurrentAttribute.Add(
new HtmlText(
this, CurrentElement, Pos - s.Length, Pos - 1, s));
1571 while (!(CurrentElement is
null))
1574 CurrentElement.EndPosition = Pos - 1;
1576 CurrentElement = CurrentElement.Parent as
HtmlElement;
1580 private static bool IsNameCharacter(
char ch)
1582 if (ch ==
'-' || ch ==
'.')
1615 if (ch ==
'\xd7' || ch ==
'\xf7')
1624 if (ch ==
'\x200c' || ch ==
'\x200d' || ch ==
'\x203f' || ch ==
'\x2040')
1667 TagName = TagName.ToUpper();
1671 case "A": Result =
new A(
this, Parent, Start);
break;
1672 case "ABBR": Result =
new Abbr(
this, Parent, Start);
break;
1673 case "ACRONYM": Result =
new Acronym(
this, Parent, Start);
break;
1677 if (this.address is
null)
1682 case "APPLET": Result =
new Applet(
this, Parent, Start);
break;
1683 case "AREA": Result =
new Area(
this, Parent, Start);
break;
1687 if (this.article is
null)
1695 if (this.aside is
null)
1703 if (this.audio is
null)
1708 case "B": Result =
new B(
this, Parent, Start);
break;
1709 case "BASE": Result =
new Base(
this, Parent, Start);
break;
1710 case "BASEFONT": Result =
new BaseFont(
this, Parent, Start);
break;
1711 case "BDI": Result =
new Bdi(
this, Parent, Start);
break;
1712 case "BDO": Result =
new Bdo(
this, Parent, Start);
break;
1713 case "BGSOUND": Result =
new BgSound(
this, Parent, Start);
break;
1714 case "BIG": Result =
new Big(
this, Parent, Start);
break;
1715 case "BLINK": Result =
new BLink(
this, Parent, Start);
break;
1716 case "BLOCKQUOTE": Result =
new BlockQuote(
this, Parent, Start);
break;
1720 if (this.body is
null)
1724 case "BR": Result =
new Br(
this, Parent, Start);
break;
1725 case "BUTTON": Result =
new Button(
this, Parent, Start);
break;
1726 case "CANVAS": Result =
new Canvas(
this, Parent, Start);
break;
1727 case "CAPTION": Result =
new Caption(
this, Parent, Start);
break;
1728 case "CENTER": Result =
new Center(
this, Parent, Start);
break;
1732 if (this.cite is
null)
1737 case "CODE": Result =
new Code(
this, Parent, Start);
break;
1738 case "COL": Result =
new Col(
this, Parent, Start);
break;
1739 case "COLGROUP": Result =
new ColGroup(
this, Parent, Start);
break;
1740 case "COMMAND": Result =
new Command(
this, Parent, Start);
break;
1741 case "CONTENT": Result =
new Elements.Content(
this, Parent, Start);
break;
1745 if (this.data is
null)
1750 case "DATALIST": Result =
new DataList(
this, Parent, Start);
break;
1751 case "DD": Result =
new Dd(
this, Parent, Start);
break;
1752 case "DEL": Result =
new Del(
this, Parent, Start);
break;
1756 if (this.details is
null)
1761 case "DFN": Result =
new Dfn(
this, Parent, Start);
break;
1765 if (this.dialog is
null)
1770 case "DIR": Result =
new Dir(
this, Parent, Start);
break;
1771 case "DIV": Result =
new Div(
this, Parent, Start);
break;
1772 case "DL": Result =
new Dl(
this, Parent, Start);
break;
1773 case "DT": Result =
new Dt(
this, Parent, Start);
break;
1774 case "ELEMENT": Result =
new Element(
this, Parent, Start);
break;
1775 case "EM": Result =
new Em(
this, Parent, Start);
break;
1776 case "EMBED": Result =
new Embed(
this, Parent, Start);
break;
1777 case "FIELDSET": Result =
new FieldSet(
this, Parent, Start);
break;
1778 case "FIGCAPTION": Result =
new FigCaption(
this, Parent, Start);
break;
1782 if (this.figure is
null)
1787 case "FONT": Result =
new Font(
this, Parent, Start);
break;
1791 if (this.footer is
null)
1799 if (this.form is
null)
1804 case "FRAME": Result =
new Frame(
this, Parent, Start);
break;
1805 case "FRAMESET": Result =
new FrameSet(
this, Parent, Start);
break;
1806 case "H1": Result =
new Hn(
this, Parent, Start, 1);
break;
1807 case "H2": Result =
new Hn(
this, Parent, Start, 2);
break;
1808 case "H3": Result =
new Hn(
this, Parent, Start, 3);
break;
1809 case "H4": Result =
new Hn(
this, Parent, Start, 4);
break;
1810 case "H5": Result =
new Hn(
this, Parent, Start, 5);
break;
1811 case "H6": Result =
new Hn(
this, Parent, Start, 6);
break;
1812 case "H7": Result =
new Hn(
this, Parent, Start, 7);
break;
1813 case "H8": Result =
new Hn(
this, Parent, Start, 8);
break;
1814 case "H9": Result =
new Hn(
this, Parent, Start, 9);
break;
1818 if (this.head is
null)
1825 if (this.header is
null)
1830 case "HGROUP": Result =
new HGroup(
this, Parent, Start);
break;
1831 case "HR": Result =
new Hr(
this, Parent, Start);
break;
1835 if (this.html is
null)
1839 case "I": Result =
new I(
this, Parent, Start);
break;
1840 case "IFRAME": Result =
new IFrame(
this, Parent, Start);
break;
1841 case "IMAGE": Result =
new Image(
this, Parent, Start);
break;
1845 if (this.img is
null)
1850 case "INPUT": Result =
new Input(
this, Parent, Start);
break;
1851 case "INS": Result =
new Ins(
this, Parent, Start);
break;
1852 case "ISINDEX": Result =
new IsIndex(
this, Parent, Start);
break;
1853 case "KBD": Result =
new Kbd(
this, Parent, Start);
break;
1854 case "KEYGEN": Result =
new Keygen(
this, Parent, Start);
break;
1855 case "LABEL": Result =
new Label(
this, Parent, Start);
break;
1856 case "LEGEND": Result =
new Legend(
this, Parent, Start);
break;
1857 case "LI": Result =
new Li(
this, Parent, Start);
break;
1861 if (this.link is
null)
1866 case "LISTING": Result =
new Listing(
this, Parent, Start);
break;
1870 if (this.main is
null)
1875 case "MAP": Result =
new Map(
this, Parent, Start);
break;
1876 case "MARK": Result =
new Mark(
this, Parent, Start);
break;
1877 case "MARQUEE": Result =
new Marquee(
this, Parent, Start);
break;
1878 case "MENU": Result =
new Menu(
this, Parent, Start);
break;
1879 case "MENUITEM": Result =
new MenuItem(
this, Parent, Start);
break;
1883 if (this.meta is
null)
1888 case "METER": Result =
new Meter(
this, Parent, Start);
break;
1889 case "MULTICOL": Result =
new MultiCol(
this, Parent, Start);
break;
1893 if (this.nav is
null)
1898 case "NEXTID": Result =
new NextId(
this, Parent, Start);
break;
1899 case "NOBR": Result =
new NoBr(
this, Parent, Start);
break;
1900 case "NOEMBED": Result =
new NoEmbed(
this, Parent, Start);
break;
1901 case "NOFRAMES": Result =
new NoFrames(
this, Parent, Start);
break;
1902 case "NOSCRIPT": Result =
new NoScript(
this, Parent, Start);
break;
1903 case "OBJECT": Result =
new Elements.Object(
this, Parent, Start);
break;
1904 case "OL": Result =
new Ol(
this, Parent, Start);
break;
1905 case "OPTGROUP": Result =
new OptGroup(
this, Parent, Start);
break;
1906 case "OPTION": Result =
new Option(
this, Parent, Start);
break;
1907 case "OUTPUT": Result =
new Output(
this, Parent, Start);
break;
1908 case "P": Result =
new P(
this, Parent, Start);
break;
1909 case "PARAM": Result =
new Param(
this, Parent, Start);
break;
1913 if (this.picture is
null)
1918 case "PLAINTEXT": Result =
new PlainText(
this, Parent, Start);
break;
1919 case "PRE": Result =
new Pre(
this, Parent, Start);
break;
1920 case "PROGRESS": Result =
new Progress(
this, Parent, Start);
break;
1921 case "Q": Result =
new Q(
this, Parent, Start);
break;
1922 case "RP": Result =
new Rp(
this, Parent, Start);
break;
1923 case "RT": Result =
new Rt(
this, Parent, Start);
break;
1924 case "RTC": Result =
new Rtc(
this, Parent, Start);
break;
1925 case "RUBY": Result =
new Ruby(
this, Parent, Start);
break;
1926 case "S": Result =
new S(
this, Parent, Start);
break;
1927 case "SAMP": Result =
new Samp(
this, Parent, Start);
break;
1931 if (this.script is
null)
1939 if (this.section is
null)
1944 case "SELECT": Result =
new Select(
this, Parent, Start);
break;
1945 case "SHADOW": Result =
new Shadow(
this, Parent, Start);
break;
1946 case "SLOT": Result =
new Slot(
this, Parent, Start);
break;
1947 case "SMALL": Result =
new Small(
this, Parent, Start);
break;
1948 case "SOURCE": Result =
new Source(
this, Parent, Start);
break;
1949 case "SPACER": Result =
new Spacer(
this, Parent, Start);
break;
1950 case "SPAN": Result =
new Span(
this, Parent, Start);
break;
1951 case "STRIKE": Result =
new Strike(
this, Parent, Start);
break;
1952 case "STRONG": Result =
new Strong(
this, Parent, Start);
break;
1956 if (this.style is
null)
1961 case "SUB": Result =
new Sub(
this, Parent, Start);
break;
1965 if (this.summary is
null)
1970 case "SUP": Result =
new Sup(
this, Parent, Start);
break;
1971 case "TABLE": Result =
new Table(
this, Parent, Start);
break;
1972 case "TBODY": Result =
new TBody(
this, Parent, Start);
break;
1973 case "TD": Result =
new Td(
this, Parent, Start);
break;
1974 case "TEMPLATE": Result =
new Template(
this, Parent, Start);
break;
1975 case "TEXTAREA": Result =
new TextArea(
this, Parent, Start);
break;
1976 case "TFOOT": Result =
new TFoot(
this, Parent, Start);
break;
1977 case "TH": Result =
new Th(
this, Parent, Start);
break;
1978 case "THEAD": Result =
new THead(
this, Parent, Start);
break;
1982 if (this.time is
null)
1990 if (this.title is
null)
1994 case "TR": Result =
new Tr(
this, Parent, Start);
break;
1995 case "TRACK": Result =
new Track(
this, Parent, Start);
break;
1996 case "TT": Result =
new Tt(
this, Parent, Start);
break;
1997 case "U": Result =
new U(
this, Parent, Start);
break;
1998 case "UL": Result =
new Ul(
this, Parent, Start);
break;
1999 case "VAR": Result =
new Var(
this, Parent, Start);
break;
2003 if (this.video is
null)
2008 case "WBR": Result =
new Wbr(
this, Parent, Start);
break;
2009 case "XMP": Result =
new Xmp(
this, Parent, Start);
break;
2010 default: Result =
new HtmlElement(
this, Parent, Start, TagName);
break;
2015 if (this.root is
null)
2019 Parent?.Add(Result);
2022 Result.EndPosition = Pos;
2033 this.root?.
Export(
Output,
new Dictionary<string, string>());
2061 Html = GetContents(
Html,
"<body",
"</body>");
2062 if (
string.IsNullOrEmpty(
Html))
2065 if (
Html.StartsWith(
"<section", StringComparison.CurrentCultureIgnoreCase) &&
2066 Html.EndsWith(
"</section>", StringComparison.CurrentCultureIgnoreCase))
2068 string Html2 =
Html.Substring(9,
Html.Length - 19).Trim();
2070 if (Html2.IndexOf(
"</section>", StringComparison.CurrentCultureIgnoreCase) < 0)
2077 private static string GetContents(
string Html,
string StartTag,
string EndTag)
2079 int i =
Html.IndexOf(StartTag, StringComparison.CurrentCultureIgnoreCase);
2081 return string.Empty;
2083 i += StartTag.Length;
2085 i =
Html.IndexOf(
'>', i);
2087 return string.Empty;
2090 int j =
Html.IndexOf(EndTag, i, StringComparison.CurrentCultureIgnoreCase);
2093 return Html.Substring(i).TrimStart();
2095 return Html.Substring(i, j - i).Trim();
2105 Html = GetContents(
Html,
"<head",
"</head>");
2106 if (
string.IsNullOrEmpty(
Html))
2109 if (
Html.StartsWith(
"<section>", StringComparison.CurrentCultureIgnoreCase) &&
2110 Html.EndsWith(
"</section>", StringComparison.CurrentCultureIgnoreCase))
Represents a DTD instruction inside the document.
Audio(HtmlDocument Document, HtmlElement Parent, int StartPosition)
AUDIO element
Html(HtmlDocument Document, HtmlElement Parent, int StartPosition)
HTML element
Script(HtmlDocument Document, HtmlElement Parent, int StartPosition)
SCRIPT element
Video(HtmlDocument Document, HtmlElement Parent, int StartPosition)
VIDEO element
static string GetHead(string Html)
Extracts the contents of the HEAD element in a HTML string.
IEnumerable< Elements.Audio > Audio
AUDIO elements found in document, or null if none found.
IEnumerable< Main > Main
HEADER elements found in document, or null if none found.
Head Head
First HEAD element of document, if found, null otherwise.
HtmlDocument(string Html)
HTML document.
HtmlElement Root
Root element.
IEnumerable< Style > Style
STYLE elements found in document, or null if none found.
IEnumerable< Nav > Nav
NAV elements found in document, or null if none found.
void Export(StringBuilder Output)
Exports the HTML document to XML.
IEnumerable< Figure > Figure
FIGURE elements found in document, or null if none found.
static string GetBody(string Html)
Extracts the contents of the BODY element in a HTML string.
void Export(XmlWriter Output)
Exports the HTML document to XML.
IEnumerable< Time > Time
TIME elements found in document, or null if none found.
IEnumerable< Article > Article
ARTICLE elements found in document, or null if none found.
IEnumerable< Picture > Picture
PICTURE elements found in document, or null if none found.
IEnumerable< ProcessingInstruction > ProcessingInstructions
Processing instructions found in document, or null if none found.
Title Title
First TITLE element of document, if found, null otherwise.
IEnumerable< Address > Address
ADDRESS elements found in document, or null if none found.
IEnumerable< Details > Details
DETAILS elements found in document, or null if none found.
IEnumerable< Aside > Aside
ASIDE elements found in document, or null if none found.
IEnumerable< Dialog > Dialog
DIALOG elements found in document, or null if none found.
string HtmlText
HTML text.
IEnumerable< Elements.Script > Script
SCRIPT elements found in document, or null if none found.
PageMetaData GetMetaData()
Gets meta-data about the page.
IEnumerable< Elements.Video > Video
VIDEO elements found in document, or null if none found.
IEnumerable< Header > Header
HEADER elements found in document, or null if none found.
IEnumerable< DtdInstruction > Dtd
DTD instructions found in document, or null if none found.
IEnumerable< Meta > Meta
META elements found in document, or null if none found.
IEnumerable< Summary > Summary
SUMMARY elements found in document, or null if none found.
Elements.Html Html
First HTML element of document, if found, null otherwise.
IEnumerable< Img > Img
IMG elements found in document, or null if none found.
Body Body
First BODY element of document, if found, null otherwise.
IEnumerable< Link > Link
LINK elements found in document, or null if none found.
IEnumerable< Form > Form
FORM elements found in document, or null if none found.
IEnumerable< Footer > Footer
FOOTER elements found in document, or null if none found.
IEnumerable< Data > Data
DATA elements found in document, or null if none found.
IEnumerable< Section > Section
SECTION elements found in document, or null if none found.
IEnumerable< Cite > Cite
CITE elements found in document, or null if none found.
Base class for all HTML elements.
virtual bool IsEmptyElement
If the element is an empty element.
override void Export(XmlWriter Output, Dictionary< string, string > Namespaces)
Exports the HTML document to XML.
string FullName
Element full name (including prefix).
override string ToString()
HTML Entity, as a unicode number string.
int EndPosition
End position of element.
Contains meta-data about a page.
Represents a Processing instruction inside the document.
A chunked list is a linked list of chunks of objects of type T .
void Add(T Item)
Adds an item to the collection.