示例#1
0
文件: Xml.cs 项目: vladimirmmm/Kraken
        public static XmlNode SelectSingleNode(XmlNode node, XPathContainer XPathContainer)
        {
            XmlNamespaceManager manager = Utilities.Xml.GetTaxonomyNamespaceManager(node.OwnerDocument);

            if (!XPathContainer.HasNamespace(manager))
            {
                return(null);
            }

            return(node.OwnerDocument.SelectSingleNode(XPathContainer.XPath, manager));
        }
示例#2
0
文件: Xml.cs 项目: vladimirmmm/Kraken
        public static List <XmlNode> SelectChildNodes(XmlNode node, XPathContainer XPathContainer)
        {
            var result = new List <XmlNode>();
            XmlNamespaceManager manager = Utilities.Xml.GetTaxonomyNamespaceManager(node.OwnerDocument);

            //var ix = XPath.IndexOf(":", StringComparison.Ordinal);
            //if (ix>-1)
            //{
            //    var ns = XPath;
            //    if (XPath.StartsWith("//", StringComparison.Ordinal))
            //    {
            //        ns = XPath.Substring(2);
            //    }
            //    ns = ns.Remove(ix);
            //    var name = XPath.Substring(ix + 1);
            //    if (ns == "*")
            //    {
            //        //XPath = "//*[local-name() = translate('" + name + "','abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')";
            //        //XPath = "*[translate(local-name(),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + name.ToUpper() + "']";
            //        //XPath = "*[matches(local-name(),'" + name + "',i)]";
            //        XPath = "*[local-name()='" + name + "']";
            //    }
            //    if (!manager.HasNamespace(ns) && ns!="*")
            //    {
            //        return result;
            //        //return node.OwnerDocument.SelectNodes("xffgh");
            //    }
            //}
            //if (XPath.Contains("*"))
            //{

            //}
            if (!XPathContainer.HasNamespace(manager))
            {
                return(result);
            }
            var nodes = node.SelectNodes(XPathContainer.XPath, manager); //.SelectNodes(XPath, manager);

            foreach (XmlNode xnode in nodes)
            {
                if (xnode.ParentNode == node)
                {
                    result.Add(xnode);
                }
            }
            return(result);
        }