Example #1
0
        public static XPathNodeType GetXPNodeType(this XmlNode node)
        {
            // Simulating behavior of deleted virtual property XmlNode.XPNodeType by using the fact
            // that each XmlNodeType has different NodeType property value
            switch (node.NodeType)
            {
            case XmlNodeType.Attribute:
            {
                XmlAttribute xmlAttribute = node as XmlAttribute;
                if (xmlAttribute != null)
                {
                    return(xmlAttribute.IsNamespace() ? XPathNodeType.Namespace : XPathNodeType.Attribute);
                }
                else
                {
                    goto default;
                }
            }

            case XmlNodeType.CDATA:
            case XmlNodeType.Text:
                return(XPathNodeType.Text);

            case XmlNodeType.Comment:
                return(XPathNodeType.Comment);

            case XmlNodeType.Document:
            case XmlNodeType.DocumentFragment:
                return(XPathNodeType.Root);

            case XmlNodeType.Element:
                return(XPathNodeType.Element);

            case XmlNodeType.ProcessingInstruction:
                return(XPathNodeType.ProcessingInstruction);

            case XmlNodeType.SignificantWhitespace:
            {
                XPathNodeType xnt = XPathNodeType.SignificantWhitespace;
                node.DecideXPNodeTypeForTextNodes(node, ref xnt);
                return(xnt);
            }

            case XmlNodeType.Whitespace:
            {
                XPathNodeType xnt = XPathNodeType.Whitespace;
                node.DecideXPNodeTypeForTextNodes(node, ref xnt);
                return(xnt);
            }

            default:
                return((XPathNodeType)(-1));
            }
        }