diff --git a/src/HtmlAgilityPack.Shared/HtmlDocument.cs b/src/HtmlAgilityPack.Shared/HtmlDocument.cs index 3c0def8b..f02758b5 100644 --- a/src/HtmlAgilityPack.Shared/HtmlDocument.cs +++ b/src/HtmlAgilityPack.Shared/HtmlDocument.cs @@ -519,7 +519,7 @@ public HtmlNode CreateElement(string name) } HtmlNode node = CreateNode(HtmlNodeType.Element); - node.Name = name; + node.SetName(name); return node; } @@ -1885,6 +1885,7 @@ private bool IsParentImplicitEnd() || nodeName == "h6" || nodeName == "header" || nodeName == "hr" + || nodeName == "li" || nodeName == "menu" || nodeName == "nav" || nodeName == "ol" diff --git a/src/HtmlAgilityPack.Shared/HtmlNode.cs b/src/HtmlAgilityPack.Shared/HtmlNode.cs index 629833c6..9ac347c4 100644 --- a/src/HtmlAgilityPack.Shared/HtmlNode.cs +++ b/src/HtmlAgilityPack.Shared/HtmlNode.cs @@ -153,17 +153,17 @@ public HtmlNode(HtmlNodeType type, HtmlDocument ownerdocument, int index) switch (type) { case HtmlNodeType.Comment: - Name = HtmlNodeTypeNameComment; + SetName(HtmlNodeTypeNameComment); _endnode = this; break; case HtmlNodeType.Document: - Name = HtmlNodeTypeNameDocument; + SetName(HtmlNodeTypeNameDocument); _endnode = this; break; case HtmlNodeType.Text: - Name = HtmlNodeTypeNameText; + SetName(HtmlNodeTypeNameText); _endnode = this; break; } @@ -600,7 +600,7 @@ public string Name if (_optimizedName == null) { if (_name == null) - Name = _ownerdocument.Text.Substring(_namestartindex, _namelength); + SetName(_ownerdocument.Text.Substring(_namestartindex, _namelength)); if (_name == null) _optimizedName = string.Empty; @@ -612,12 +612,18 @@ public string Name return _optimizedName; } - set - { - _name = value; - _optimizedName = null; + set + { + SetName(value); + SetChanged(); } - } + } + + internal void SetName(string value) + { + _name = value; + _optimizedName = null; + } /// /// Gets the HTML node immediately following this element. @@ -1046,7 +1052,7 @@ public HtmlNode CloneNode(string newName, bool deep) } HtmlNode node = CloneNode(deep); - node.Name = newName; + node.SetName(newName); return node; } @@ -1058,7 +1064,7 @@ public HtmlNode CloneNode(string newName, bool deep) public HtmlNode CloneNode(bool deep) { HtmlNode node = _ownerdocument.CreateNode(_nodetype); - node.Name = OriginalName; + node.SetName(OriginalName); switch (_nodetype) { @@ -2159,10 +2165,9 @@ public void SetParent(HtmlNode parent) } } -#endregion - -#region Internal Methods + #endregion + #region Internal Methods internal void SetChanged() { _changed = true;