internal XmlElement FindTypeNode(XmlElement node)
{
string strType;
XmlNode vn;
XmlNode vnRoof;
Debug.Assert(FEqualIdentity(node, Keywords.XDR_ELEMENT, Keywords.XDRNS) ||
FEqualIdentity(node, Keywords.XDR_SCHEMA, Keywords.XDRNS) ||
FEqualIdentity(node, Keywords.XDR_ATTRIBUTE, Keywords.XDRNS) ||
FEqualIdentity(node, Keywords.XDR_ELEMENTTYPE, Keywords.XDRNS),
"Invalid node type " + node.LocalName);
if (FEqualIdentity(node, Keywords.XDR_ELEMENTTYPE, Keywords.XDRNS))
return node;
strType = node.GetAttribute(Keywords.TYPE);
if (FEqualIdentity(node, Keywords.XDR_ELEMENT, Keywords.XDRNS) ||
FEqualIdentity(node, Keywords.XDR_ATTRIBUTE, Keywords.XDRNS))
{
if (strType == null || strType.Length == 0)
return null;
// Find an ELEMENTTYPE or ATTRIBUTETYPE with name=strType
vn = node.OwnerDocument.FirstChild;
vnRoof = node.OwnerDocument;
while (vn != vnRoof)
{
if ((FEqualIdentity(vn, Keywords.XDR_ELEMENTTYPE, Keywords.XDRNS) &&
FEqualIdentity(node, Keywords.XDR_ELEMENT, Keywords.XDRNS)) ||
(FEqualIdentity(vn, Keywords.XDR_ATTRIBUTETYPE, Keywords.XDRNS) &&
FEqualIdentity(node, Keywords.XDR_ATTRIBUTE, Keywords.XDRNS)))
{
if (vn is XmlElement && ((XmlElement)vn).GetAttribute(Keywords.NAME) == strType)
return (XmlElement)vn;
}
// Move vn node
if (vn.FirstChild != null)
vn = vn.FirstChild;
else if (vn.NextSibling != null)
vn = vn.NextSibling;
else
{
while (vn != vnRoof)
{
vn = vn.ParentNode;
if (vn.NextSibling != null)
{
vn = vn.NextSibling;
break;
}
}
}
}
return null;
}
return null;
}