示例#1
0
        /// <summary>
        /// Add a new node related to this. Adds a child past the LastChild.
        ///
        /// NOTE: the node to be added is passed by pointer, and will be
        /// henceforth owned (and deleted) by tinyXml. This method is efficient
        /// and avoids an extra copy, but should be used with care as it
        /// uses a different memory model than the other insert functions.
        /// </summary>
        /// <seealso cref="InsertEndChild"/>
        public TiXmlNode LinkEndChild(TiXmlNode node)
        {
            //assert( node.parent == 0 || node.parent == this );
            //assert( node.GetDocument() == 0 || node.GetDocument() == this.GetDocument() );

            if (node.Type() == TiXmlNode.NodeType.DOCUMENT)
            {
                //delete node;
                if (GetDocument() != null)
                {
                    GetDocument().SetError(ErrorType.TIXML_ERROR_DOCUMENT_TOP_ONLY, null, 0, null, TiXmlEncoding.TIXML_ENCODING_UNKNOWN);
                }
                return(null);
            }

            node.parent = this;

            node.prev = lastChild;
            node.next = null;

            if (lastChild != null)
            {
                lastChild.next = node;
            }
            else
            {
                firstChild = node;                                      // it was an empty list.
            }
            lastChild = node;
            return(node);
        }
示例#2
0
        /// <summary>
        /// Add a new node related to this. Adds a child past the LastChild.
        /// Returns a pointer to the new object or NULL if an error occurred.
        /// </summary>
        public TiXmlNode InsertEndChild(TiXmlNode addThis)
        {
            if (addThis.Type() == TiXmlNode.NodeType.DOCUMENT)
            {
                if (GetDocument() != null)
                {
                    GetDocument().SetError(ErrorType.TIXML_ERROR_DOCUMENT_TOP_ONLY, null, 0, null, TiXmlEncoding.TIXML_ENCODING_UNKNOWN);
                }
                return(null);
            }
            TiXmlNode node = addThis.Clone();

            if (node == null)
            {
                return(null);
            }
            return(LinkEndChild(node));
        }
示例#3
0
        /// <summary>
        /// Add a new node related to this. Adds a child after the specified child.
        /// Returns a pointer to the new object or NULL if an error occurred.
        /// </summary>
        public TiXmlNode InsertAfterChild(TiXmlNode afterThis, TiXmlNode addThis)
        {
            if (afterThis == null || afterThis.parent != this)
            {
                return(null);
            }
            if (addThis.Type() == TiXmlNode.NodeType.DOCUMENT)
            {
                if (GetDocument() != null)
                {
                    GetDocument().SetError(ErrorType.TIXML_ERROR_DOCUMENT_TOP_ONLY, null, 0, null, TiXmlEncoding.TIXML_ENCODING_UNKNOWN);
                }
                return(null);
            }

            TiXmlNode node = addThis.Clone();

            if (node == null)
            {
                return(null);
            }
            node.parent = this;

            node.prev = afterThis;
            node.next = afterThis.next;
            if (afterThis.next != null)
            {
                afterThis.next.prev = node;
            }
            else
            {
                //assert( lastChild == afterThis );
                lastChild = node;
            }
            afterThis.next = node;
            return(node);
        }
示例#4
0
        /// <summary>
        /// Add a new node related to this. Adds a child before the specified child.
        /// Returns a pointer to the new object or NULL if an error occurred.
        /// </summary>
        public TiXmlNode InsertBeforeChild(TiXmlNode beforeThis, TiXmlNode addThis)
        {
            if (beforeThis == null || beforeThis.parent != this)
            {
                return(null);
            }
            if (addThis.Type() == TiXmlNode.NodeType.DOCUMENT)
            {
                if (GetDocument() != null)
                {
                    GetDocument().SetError(ErrorType.TIXML_ERROR_DOCUMENT_TOP_ONLY, null, 0, null, TiXmlEncoding.TIXML_ENCODING_UNKNOWN);
                }
                return(null);
            }

            TiXmlNode node = addThis.Clone();

            if (node == null)
            {
                return(null);
            }
            node.parent = this;

            node.next = beforeThis;
            node.prev = beforeThis.prev;
            if (beforeThis.prev != null)
            {
                beforeThis.prev.next = node;
            }
            else
            {
                //assert( firstChild == beforeThis );
                firstChild = node;
            }
            beforeThis.prev = node;
            return(node);
        }