private static bool IsDescendant(XmlNode top, XmlNode bottom) {
for (;;) {
XmlNode parent = bottom.ParentNode;
if (parent == null) {
XmlAttribute attribute = bottom as XmlAttribute;
if (attribute == null) {
break;
}
parent = attribute.OwnerElement;
if (parent == null) {
break;
}
}
bottom = parent;
if (top == bottom) {
return true;
}
}
return false;
}