Esempio n. 1
0
 public object importNode(DOMNode importedNode, bool deep)
 {
     if (importedNode.IsAssociated)
     {
         return(DOMNode.Create(XmlDocument.ImportNode(importedNode.XmlNode, deep)));
     }
     else
     {
         importedNode.Associate(XmlDocument);
         return(importedNode);
     }
 }
Esempio n. 2
0
        public static DObject ImportSimpleXml(DObject node)
        {
            SimpleXMLElement sxe_node = node as SimpleXMLElement;

            if (sxe_node == null)
            {
                PhpException.InvalidImplicitCast(node, "SimpleXMLElement", "node");
                return(null);
            }

            return((DObject)DOMNode.Create(sxe_node.XmlElement));
        }
Esempio n. 3
0
        /// <summary>
        /// Converts a W3C .NET object to the corresponding W3C PHP object.
        /// </summary>
        public static object DotNetToPhp(object arg)
        {
            // Result Tree Fragment (XSLT) / Node (XPath)
            XPathNavigator nav = arg as XPathNavigator;

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

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

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

                return(array);
            }

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

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

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

                return(array);
            }

            // Number (XPath), Boolean (XPath), String (XPath)
            return(arg);
        }
Esempio n. 4
0
        public object getElementsByTagNameNS(string namespaceUri, string localName)
        {
            DOMNodeList list = new DOMNodeList();

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

            return(list);
        }
Esempio n. 5
0
        private DOMNodeList IteratorToList(XPathNodeIterator iterator)
        {
            DOMNodeList list = new DOMNodeList();

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

            return(list);
        }
Esempio n. 6
0
        public object getElementsByTagName(string name)
        {
            DOMNodeList list = new DOMNodeList();

            if (IsAssociated)
            {
                // enumerate elements in the default namespace
                foreach (XmlNode node in XmlElement.GetElementsByTagName(name))
                {
                    IXmlDomNode 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))
                        {
                            IXmlDomNode dom_node = DOMNode.Create(node);
                            if (dom_node != null)
                            {
                                list.AppendNode(dom_node);
                            }
                        }
                    }
                }
            }

            return(list);
        }