Beispiel #1
0
        /// <summary>
        /// Converts a W3C PHP object to a corresponding string.
        /// </summary>
        public static string /*!*/ PhpToString(Context ctx, PhpValue arg)
        {
            if (arg.IsObject)
            {
                // Node* (XPath)
                var node = arg.Object as DOMNode;
                if (node != null)
                {
                    return(node.XmlNode.Value);
                }

                // Node Set (XPath), Result Tree Fragment (XSLT)
                DOMNodeList list = arg.Object as DOMNodeList;
                if (list != null)
                {
                    if (list.length == 0)
                    {
                        return(String.Empty);
                    }
                    return(list.item(0).XmlNode.Value);
                }
            }

            // any other object
            return(arg.ToString(ctx));
        }
Beispiel #2
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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        /// <summary>
        /// Converts a W3C PHP object to the corresponding W3C .NET object.
        /// </summary>
        public static object /*!*/ PhpToDotNet(Context ctx, PhpValue arg)
        {
            if (arg.IsNull)
            {
                return(String.Empty);
            }

            // Node* (XPath)
            if (arg.IsObject)
            {
                var node = arg.Object as DOMNode;
                if (node != null)
                {
                    return(node.XmlNode.CreateNavigator());
                }

                // Node Set (XPath), Result Tree Fragment (XSLT)
                DOMNodeList list = arg.Object as DOMNodeList;
                if (list != null)
                {
                    XPathNavigator[] navs = new XPathNavigator[list.length];

                    for (int i = 0; i < list.length; i++)
                    {
                        navs[i] = list.item(i).XmlNode.CreateNavigator();
                    }

                    return(navs);
                }

                // any other object
                return(arg.ToString(ctx));
            }

            // TODO: Handle PhpArray separately?
            // String (XPath), Boolean (XPath), Number (XPath)
            return(arg.ToClr());
        }