Esempio n. 1
0
        /// <summary>
        /// Converts a W3C PHP object to a corresponding string.
        /// </summary>
        public static string /*!*/ PhpToString(object arg)
        {
            // Node* (XPath)
            IXmlDomNode node = arg as IXmlDomNode;

            if (node != null)
            {
                return(node.UnderlyingObject.Value);
            }

            // Node Set (XPath), Result Tree Fragment (XSLT)
            DOMNodeList list = arg as DOMNodeList;

            if (list != null)
            {
                if (list.length == 0)
                {
                    return(String.Empty);
                }
                return(list.item(0).UnderlyingObject.Value);
            }

            // any other object
            return(PHP.Core.Convert.ObjectToString(arg));
        }
Esempio n. 2
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. 3
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. 4
0
        /// <summary>
        /// Converts a W3C PHP object to the corresponding W3C .NET object.
        /// </summary>
        public static object /*!*/ PhpToDotNet(object arg)
        {
            if (arg == null)
            {
                return(String.Empty);
            }

            // Node* (XPath)
            IXmlDomNode node = arg as IXmlDomNode;

            if (node != null)
            {
                return(node.UnderlyingObject.CreateNavigator());
            }

            // Node Set (XPath), Result Tree Fragment (XSLT)
            DOMNodeList list = arg as DOMNodeList;

            if (list != null)
            {
                XPathNavigator[] navs = new XPathNavigator[list.length];

                int i = 0;
                foreach (var pair in (IEnumerable <KeyValuePair <object, object> >)list)
                {
                    navs[i++] = ((IXmlDomNode)pair.Value).UnderlyingObject.CreateNavigator();
                }

                return(navs);
            }

            // any other object
            IPhpVariable var = arg as IPhpVariable;

            if (var != null)
            {
                return(var.ToString());
            }

            // String (XPath), Boolean (XPath), Number (XPath)
            return(arg);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
		public object getElementsByTagNameNS(string namespaceUri, string localName)
		{
			DOMNodeList list = new DOMNodeList();

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

			return list;
		}
Esempio n. 7
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;
		}
Esempio n. 8
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;
		}