internal ElementNode FindTopmostParent(List<string> tagNames, bool ignoreCase) {
ElementNode topmostNode = this;
var node = this;
if (tagNames.Count > 1)
return Root; // Edge case, can be optimized later if necessary.
foreach (string tag in tagNames) {
while (!(node is RootNode)) {
if (String.Compare(tag, node.QualifiedName, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) {
topmostNode = node.Parent;
// Don't break and instead continue up to the topmost
// matching node so we properly handle insertion of </a>
// into the innermost element in <a><a><a>|</a></a></a>
}
node = node.Parent;
}
}
return topmostNode;
}