Exemplo 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);
     }
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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;
			}
		}
Exemplo n.º 4
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;
		}