コード例 #1
0
ファイル: DOMXPath.cs プロジェクト: hungud/peachpie
        // TODO: Remove when IteratorToList works
        private DOMNodeList QueryInternal(XmlNode contextnode, string expr, XmlNamespaceManager xmlNamespaceManager)
        {
            if (contextnode == null)
            {
                contextnode = ((XmlDocument)XPathNavigator.UnderlyingObject).DocumentElement;
            }

            XmlNodeList xmlList;

            try
            {
                // We have to re-run the query in order to get access to the nodes
                xmlList = contextnode.SelectNodes(expr, xmlNamespaceManager);
            }
            catch (Exception ex)
            {
                PhpException.Throw(PhpError.E_WARNING, ex.Message);
                return(null);
            }

            var domList = new DOMNodeList();

            foreach (XmlNode node in xmlList)
            {
                domList.AppendNode(DOMNode.Create(node));
            }

            return(domList);
        }
コード例 #2
0
        /// <summary>
        /// Gets all descendant elements with the matching tag name.
        /// </summary>
        /// <param name="name">The tag name. Use <B>*</B> to return all elements within the element tree.</param>
        /// <returns>A <see cref="DOMNodeList"/>.</returns>
        public virtual DOMNodeList getElementsByTagName(string name)
        {
            DOMNodeList list = new DOMNodeList();

            if (IsAssociated)
            {
                // enumerate elements in the default namespace
                foreach (XmlNode node in XmlElement.GetElementsByTagName(name))
                {
                    var dom_node = DOMNode.Create(node);
                    if (dom_node != null)
                    {
                        list.AppendNode(dom_node);
                    }
                }

                // enumerate all namespaces
                XPathNavigator    navigator = XmlElement.CreateNavigator();
                XPathNodeIterator iterator  = navigator.Select("//namespace::*[not(. = ../../namespace::*)]");

                while (iterator.MoveNext())
                {
                    string prefix = iterator.Current.Name;
                    if (!String.IsNullOrEmpty(prefix) && prefix != "xml")
                    {
                        // enumerate elements in this namespace
                        foreach (XmlNode node in XmlElement.GetElementsByTagName(name, iterator.Current.Value))
                        {
                            var dom_node = DOMNode.Create(node);
                            if (dom_node != null)
                            {
                                list.AppendNode(dom_node);
                            }
                        }
                    }
                }
            }

            return(list);
        }
コード例 #3
0
        /// <summary>
        /// Gets all descendant elements with the matching namespace URI and local name.
        /// </summary>
        /// <param name="namespaceUri">The namespace URI.</param>
        /// <param name="localName">The local name. Use <B>*</B> to return all elements within the element tree.</param>
        /// <returns>A <see cref="DOMNodeList"/>.</returns>
        public virtual DOMNodeList getElementsByTagNameNS(string namespaceUri, string localName)
        {
            DOMNodeList list = new DOMNodeList();

            foreach (XmlNode node in XmlDocument.GetElementsByTagName(localName, namespaceUri))
            {
                var dom_node = DOMNode.Create(node);
                if (dom_node != null)
                {
                    list.AppendNode(dom_node);
                }
            }

            return(list);
        }
コード例 #4
0
        private DOMNodeList IteratorToList(XPathNodeIterator iterator)
        {
            DOMNodeList list = new DOMNodeList();

            while (iterator.MoveNext())
            {
                IHasXmlNode has_node = iterator.Current as IHasXmlNode;
                if (has_node != null)
                {
                    var node = DOMNode.Create(has_node.GetNode());
                    if (node != null)
                    {
                        list.AppendNode(node);
                    }
                }
            }

            return(list);
        }