Esempio n. 1
0
        // 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Converts a <see cref="SimpleXMLElement"/> object to a <see cref="DOMElement"/>.
        /// </summary>
        public static object dom_import_simplexml(SimpleXMLElement node)
        {
            if (node == null)
            {
                PhpException.InvalidImplicitCast(nameof(node), "SimpleXMLElement", "dom_import_simplexml");
                return(null);
            }

            return(DOMNode.Create(node.XmlElement));
        }
Esempio n. 3
0
 /// <summary>
 /// Imports a node from another document to the current document.
 /// </summary>
 /// <param name="importedNode">The node being imported.</param>
 /// <param name="deep"><B>True</B> to perform deep clone; otheriwse <B>false</B>.</param>
 /// <returns>The imported <see cref="DOMNode"/>.</returns>
 public virtual DOMNode importNode(DOMNode importedNode, bool deep = false)
 {
     if (importedNode.IsAssociated)
     {
         return(DOMNode.Create(XmlDocument.ImportNode(importedNode.XmlNode, deep)));
     }
     else
     {
         importedNode.Associate(XmlDocument);
         return(importedNode);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Converts a W3C .NET object to the corresponding W3C PHP object.
        /// </summary>
        public static PhpValue DotNetToPhp(object arg)
        {
            // Result Tree Fragment (XSLT) / Node (XPath)
            XPathNavigator nav = arg as XPathNavigator;

            if (nav != null)
            {
                return(PhpValue.FromClass(DOMNode.Create(nav.UnderlyingObject as XmlNode)));
            }

            // Node Set (XPath) - XPathNavigator[]
            XPathNavigator[] navs = arg as XPathNavigator[];
            if (navs != null)
            {
                PhpArray array = new PhpArray(navs.Length);

                for (int i = 0; i < navs.Length; i++)
                {
                    var node = DOMNode.Create(navs[i].UnderlyingObject as XmlNode);
                    if (node != null)
                    {
                        array.Add(node);
                    }
                }

                return(PhpValue.Create(array));
            }

            // Node Set (XPath) - XPathNodeIterator
            XPathNodeIterator iter = arg as XPathNodeIterator;

            if (iter != null)
            {
                PhpArray array = new PhpArray();

                foreach (XPathNavigator navigator in iter)
                {
                    var node = DOMNode.Create(navigator.UnderlyingObject as XmlNode);
                    if (node != null)
                    {
                        array.Add(node);
                    }
                }

                return(PhpValue.Create(array));
            }

            // Number (XPath), Boolean (XPath), String (XPath)
            return(PhpValue.FromClr(arg));
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
 public static DOMElement dom_import_simplexml(SimpleXMLElement node) => (DOMElement)DOMNode.Create(node.XmlElement);