コード例 #1
0
ファイル: XPathHelper.cs プロジェクト: layomia/dotnet_runtime
        private static void AddAttributes(SimpleXmlNodeList list, XmlNode node, bool onlyNamespaces)
        {
            XmlAttributeCollection attributes = node.Attributes;

            if (attributes != null)
            {
                for (int i = 0; i < attributes.Count; i++)
                {
                    XmlAttribute a = attributes[i];
                    if (!onlyNamespaces || IsNamespaceNode(a))
                    {
                        list.Add(a);
                    }
                }
            }
        }
コード例 #2
0
ファイル: XPathHelper.cs プロジェクト: layomia/dotnet_runtime
        public static SimpleXmlNodeList CreateSubtreeNodeList(XmlNode root, string elementToStartAt)
        {
            XmlElement inclusionRoot = FindElement(root, elementToStartAt);

            if (inclusionRoot == null)
            {
                throw new ArgumentException("elementToStartAt", elementToStartAt + " not found in document");
            }

            SimpleXmlNodeList list = GetAllDescendents(inclusionRoot);

            for (XmlNode node = inclusionRoot.ParentNode; node != null; node = node.ParentNode)
            {
                AddAttributes(list, node, true);
            }

            return(list);
        }
コード例 #3
0
ファイル: XPathHelper.cs プロジェクト: layomia/dotnet_runtime
        public static SimpleXmlNodeList GetAllDescendents(XmlNode root)
        {
            SimpleXmlNodeList bfsQueue = new SimpleXmlNodeList();

            bfsQueue.Add(root);
            for (int i = 0; i < bfsQueue.Count; i++)
            {
                XmlNode node = bfsQueue[i];
                for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling)
                {
                    bfsQueue.Add(child);
                }

                AddAttributes(bfsQueue, node, false);
            }

            return(bfsQueue);
        }