Beispiel #1
0
        public object removeChild(DOMNode oldNode)
        {
            // check for readonly node
            if (XmlNode.IsReadOnly)
            {
                DOMException.Throw(ExceptionCode.DomModificationNotAllowed);
                return(false);
            }

            try
            {
                XmlNode.RemoveChild(oldNode.XmlNode);
            }
            catch (ArgumentException)
            {
                DOMException.Throw(ExceptionCode.NotFound);
                return(false);
            }

            return(oldNode);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public object appendChild(DOMNode newNode)
        {
            bool is_fragment;

            if (newNode is DOMDocumentFragment)
            {
                if (!newNode.IsAssociated || !newNode.XmlNode.HasChildNodes)
                {
                    PhpException.Throw(PhpError.Warning, Resources.DocumentFragmentEmpty);
                    return(false);
                }
                is_fragment = true;
            }
            else
            {
                is_fragment = false;
            }

            XmlNode result = CheckedChildOperation(newNode, null, delegate(DOMNode _newNode, DOMNode _)
            {
                return(XmlNode.AppendChild(_newNode.XmlNode));
            });

            if (result == null)
            {
                return(false);
            }
            if (is_fragment)
            {
                return(Create(result));
            }
            else
            {
                return(newNode);
            }
        }
Beispiel #4
0
        public object query(string expr, [Optional] DOMNode context)
        {
            XPathNavigator navigator = GetNavigator(context);

            if (navigator == null)
            {
                return(false);
            }

            XPathNodeIterator iterator;

            try
            {
                iterator = navigator.Select(expr, XmlNamespaceManager);
            }
            catch (Exception ex)
            {
                DOMException.Throw(ExceptionCode.SyntaxError, ex.Message);
                return(false);
            }

            // create the resulting node list
            return(IteratorToList(iterator));
        }
Beispiel #5
0
        public object insertBefore(DOMNode newNode, [Optional][Nullable] DOMNode refNode)
        {
            bool is_fragment;

            if (newNode is DOMDocumentFragment)
            {
                if (!newNode.IsAssociated || !newNode.XmlNode.HasChildNodes)
                {
                    PhpException.Throw(PhpError.Warning, Resources.DocumentFragmentEmpty);
                    return(false);
                }
                is_fragment = true;
            }
            else
            {
                is_fragment = false;
            }

            XmlNode result = CheckedChildOperation(newNode, refNode, delegate(DOMNode _newNode, DOMNode _refNode)
            {
                return(XmlNode.InsertBefore(_newNode.XmlNode, (_refNode == null ? null : _refNode.XmlNode)));
            });

            if (result == null)
            {
                return(false);
            }
            if (is_fragment)
            {
                return(Create(result));
            }
            else
            {
                return(newNode);
            }
        }
Beispiel #6
0
		public object insertBefore(DOMNode newNode, [Optional][Nullable] DOMNode refNode)
		{
			bool is_fragment;
			if (newNode is DOMDocumentFragment)
			{
				if (!newNode.IsAssociated || !newNode.XmlNode.HasChildNodes)
				{
					PhpException.Throw(PhpError.Warning, Resources.DocumentFragmentEmpty);
					return false;
				}
				is_fragment = true;
			}
			else is_fragment = false;

			XmlNode result = CheckedChildOperation(newNode, refNode, delegate(DOMNode _newNode, DOMNode _refNode)
			{
				return XmlNode.InsertBefore(_newNode.XmlNode, (_refNode == null ? null : _refNode.XmlNode));
			});

			if (result == null) return false;
			if (is_fragment) return Create(result);
			else return newNode;
		}
Beispiel #7
0
		public void handle(int operation, string key, object data, DOMNode src, DOMNode dst)
		{
			PhpException.Throw(PhpError.Warning, Resources.NotYetImplemented);
		}
Beispiel #8
0
		public void isEqualNode(DOMNode anotherNode)
		{
			PhpException.Throw(PhpError.Warning, Resources.NotYetImplemented);
		}
Beispiel #9
0
		public void compareDocumentPosition(DOMNode anotherNode)
		{
			PhpException.Throw(PhpError.Warning, Resources.NotYetImplemented);
		}
Beispiel #10
0
		public void renameNode(DOMNode node, string namespaceUri, string qualifiedName)
		{
			PhpException.Throw(PhpError.Warning, Resources.NotYetImplemented);
		}
Beispiel #11
0
 public void renameNode(DOMNode node, string namespaceUri, string qualifiedName)
 {
     PhpException.Throw(PhpError.Warning, Resources.NotYetImplemented);
 }
Beispiel #12
0
 public object expand([Optional] DOMNode basenode)
 {
     return(false);
 }
Beispiel #13
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;
			}
		}
Beispiel #14
0
		/// <summary>
		/// Performs a child-adding action with error checks.
		/// </summary>
		private XmlNode CheckedChildOperation(DOMNode/*!*/ newNode, DOMNode auxNode, NodeAction/*!*/ action)
		{
			newNode.Associate(XmlNode.OwnerDocument != null ? XmlNode.OwnerDocument : (XmlDocument)XmlNode);

			// check for readonly node
			if (XmlNode.IsReadOnly || (newNode.XmlNode.ParentNode != null && newNode.XmlNode.ParentNode.IsReadOnly))
			{
				DOMException.Throw(ExceptionCode.DomModificationNotAllowed);
				return null;
			}

			// check for owner document mismatch
			if (XmlNode.OwnerDocument != null ?
				XmlNode.OwnerDocument != newNode.XmlNode.OwnerDocument :
				XmlNode != newNode.XmlNode.OwnerDocument)
			{
				DOMException.Throw(ExceptionCode.WrongDocument);
				return null;
			}

			XmlNode result;
			try
			{
				result = action(newNode, auxNode);
			}
			catch (InvalidOperationException)
			{
				// the current node is of a type that does not allow child nodes of the type of the newNode node
				// or the newNode is an ancestor of this node. 
				DOMException.Throw(ExceptionCode.BadHierarchy);
				return null;
			}
			catch (ArgumentException)
			{
				// check for newNode == this which System.Xml reports as ArgumentException
				if (newNode.XmlNode == XmlNode) DOMException.Throw(ExceptionCode.BadHierarchy);
				else
				{
					// the refNode is not a child of this node
					DOMException.Throw(ExceptionCode.NotFound);
				}
				return null;
			}

			return result;
		}
Beispiel #15
0
		private XPathNavigator GetNavigator(DOMNode context)
		{
			if (context == null) return XPathNavigator;
			else
			{
				XmlNode node = context.XmlNode;

				if (node.OwnerDocument != (XmlDocument)XPathNavigator.UnderlyingObject)
				{
					DOMException.Throw(ExceptionCode.WrongDocument);
					return null;
				}

				return node.CreateNavigator();
			}
		}
Beispiel #16
0
 public void isEqualNode(DOMNode anotherNode)
 {
     PhpException.Throw(PhpError.Warning, Resources.NotYetImplemented);
 }
Beispiel #17
0
 public void compareDocumentPosition(DOMNode anotherNode)
 {
     PhpException.Throw(PhpError.Warning, Resources.NotYetImplemented);
 }
Beispiel #18
0
 public object isSameNode(DOMNode anotherNode)
 {
     return(XmlNode == anotherNode.XmlNode);
 }
Beispiel #19
0
 public void handle(int operation, string key, object data, DOMNode src, DOMNode dst)
 {
     PhpException.Throw(PhpError.Warning, Resources.NotYetImplemented);
 }
Beispiel #20
0
		public object replaceChild(DOMNode newNode, DOMNode oldNode)
		{
			XmlNode result = CheckedChildOperation(newNode, oldNode, delegate(DOMNode _newNode, DOMNode _oldNode)
			{
				return XmlNode.ReplaceChild(_newNode.XmlNode, _oldNode.XmlNode);
			});

			if (result == null) return false;
			if (newNode is DOMDocumentFragment) return Create(result);
			else return newNode;
		}
Beispiel #21
0
		public void adoptNode(DOMNode source)
		{
			PhpException.Throw(PhpError.Warning, Resources.NotYetImplemented);
		}
Beispiel #22
0
		public object appendChild(DOMNode newNode)
		{
			bool is_fragment;
			if (newNode is DOMDocumentFragment)
			{
				if (!newNode.IsAssociated || !newNode.XmlNode.HasChildNodes)
				{
					PhpException.Throw(PhpError.Warning, Resources.DocumentFragmentEmpty);
					return false;
				}
				is_fragment = true;
			}
			else is_fragment = false;

			XmlNode result = CheckedChildOperation(newNode, null, delegate(DOMNode _newNode, DOMNode _)
			{
				return XmlNode.AppendChild(_newNode.XmlNode);
			});

			if (result == null) return false;
			if (is_fragment) return Create(result);
			else return newNode;
		}
Beispiel #23
0
 public void adoptNode(DOMNode source)
 {
     PhpException.Throw(PhpError.Warning, Resources.NotYetImplemented);
 }
Beispiel #24
0
		public object removeChild(DOMNode oldNode)
		{
			// check for readonly node
			if (XmlNode.IsReadOnly)
			{
				DOMException.Throw(ExceptionCode.DomModificationNotAllowed);
				return false;
			}

			try
			{
				XmlNode.RemoveChild(oldNode.XmlNode);
			}
			catch (ArgumentException)
			{
				DOMException.Throw(ExceptionCode.NotFound);
				return false;
			}

			return oldNode;
		}
Beispiel #25
0
 public void setNamedItemNS(DOMNode item)
 {
     PhpException.Throw(PhpError.Warning, Resources.NotYetImplemented);
 }
Beispiel #26
0
		public object isSameNode(DOMNode anotherNode)
		{
			return (XmlNode == anotherNode.XmlNode);
		}