Example #1
0
 public override Node RemoveChild(Node child)
 {
     throw new DOMException(ErrorCode.HierarchyRequestError);
 }
 public override Node InsertChild(int index, Node child)
 {
     throw new DOMException(ErrorCode.NotSupported);
 }
 public override Node AppendChild(Node child)
 {
     throw new DOMException(ErrorCode.NotSupported);
 }
Example #4
0
        /// <summary>
        /// Copies all (Node) properties of the source to the target.
        /// </summary>
        /// <param name="source">The source node.</param>
        /// <param name="target">The target node.</param>
        /// <param name="deep">Is a deep-copy required?</param>
        protected static void CopyProperties(Node source, Node target, Boolean deep)
        {
            target._baseURI = source._baseURI;
            target._name = source._name;
            target._type = source.NodeType;
            target._ns = source._ns;

            if (deep)
            {
                for (int i = 0; i < source._children.Length; i++)
                    target._children.Add(source._children[i].CloneNode(true));

                for (int i = 0; i < source._attributes.Length; i++)
                    target._attributes.SetNamedItem(source._attributes[i].CloneNode(true) as Attr);
            }
        }
Example #5
0
        /// <summary>
        /// Compares the relative position in a node list.
        /// </summary>
        /// <param name="list">The node list as a base.</param>
        /// <param name="nodeA">The first node.</param>
        /// <param name="nodeB">The other node.</param>
        /// <returns>The position.</returns>
        static DocumentPosition CompareRelativePositionInNodeList(NodeList list, Node nodeA, Node nodeB)
        {
            var aPos = -1;
            var bPos = -1;

            for (int i = 0; i < list.Length; i++)
            {
                if (aPos == -1 && list[i].Contains(nodeA))
                    aPos = i;

                if (bPos == -1 && list[i].Contains(nodeB))
                    bPos = i;
            }

            if (aPos < bPos)
                return DocumentPosition.Preceding;
            else if (bPos < aPos)
                return DocumentPosition.Following;
            else if (aPos != -1 && bPos != -1)
                return CompareRelativePositionInNodeList(list[aPos].ChildNodes, nodeA, nodeB);

            return DocumentPosition.Disconnected;
        }
Example #6
0
        public virtual Boolean IsEqualNode(Node otherNode)
        {
            if (this._baseURI != otherNode._baseURI)
                return false;

            if (this._name != otherNode._name)
                return false;

            if (this._ns != otherNode._ns)
                return false;

            if (this._attributes.Length != otherNode._attributes.Length)
                return false;

            if (this._children.Length != otherNode._children.Length)
                return false;

            for (int i = 0; i < this._attributes.Length; i++)
            {
                if(!this._attributes[i].IsEqualNode(otherNode._attributes[i]))
                    return false;
            }

            for (int i = 0; i < this._children.Length; i++)
            {
                if(!this._children[i].IsEqualNode(otherNode._children[i]))
                    return false;
            }

            return true;
        }
Example #7
0
        public virtual Node ReplaceChild(Node newChild, Node oldChild)
        {
            if (newChild is Attr || newChild is Document || newChild.Contains(this))
                throw new DOMException(ErrorCode.HierarchyRequestError);
            else if (newChild == oldChild)
                return oldChild;
            else if (newChild.ParentNode != null)
                throw new DOMException(ErrorCode.InUse);

            var n = _children.Length;

            for (int i = 0; i < n; i++)
            {
                if (_children[i] == oldChild)
                {
                    RemoveChild(oldChild);
                    InsertChild(i, newChild);
                    return oldChild;
                }
            }

            return null;
        }
Example #8
0
 public RangePosition ComparePoint(Node node, int offset)
 {
     throw new NotImplementedException();
 }
Example #9
0
 public bool IntersectsNode(Node node)
 {
     throw new NotImplementedException();
 }
Example #10
0
 public void SurroundContents(Node newParent)
 {
     throw new NotImplementedException();
 }
Example #11
0
 public bool IsPointInRange(Node node, int offset)
 {
     throw new NotImplementedException();
 }
Example #12
0
 public void InsertNode(Node node)
 {
     throw new NotImplementedException();
 }
Example #13
0
        /// <summary>
        /// Builds a list of nodes according with 8.4 Parsing HTML fragments.
        /// </summary>
        /// <param name="sourceCode">The string to use as source code.</param>
        /// <param name="context">The context node to use.</param>
        /// <returns>A list of parsed nodes.</returns>
        public static NodeList HtmlFragment(String sourceCode, Node context = null)
        {
            var source = new SourceManager(sourceCode);
            var doc = new HTMLDocument();
            var db = new DocumentBuilder(source, doc);

            if (context != null)
            {
                if (context.OwnerDocument != null && context.OwnerDocument.QuirksMode != QuirksMode.Off)
                    doc.QuirksMode = context.OwnerDocument.QuirksMode;

                //    Note: For performance reasons, an implementation that does not report errors and that uses
                //          the actual state machine described in this specification directly could use the
                //          PLAINTEXT state instead of the RAWTEXT and script data states where those are mentioned
                //          in the list above. Except for rules regarding parse errors, they are equivalent, since
                //          there is no appropriate end tag token in the fragment case, yet they involve far
                //          fewer state transitions.

                ((HtmlParser)db.parser).SwitchToFragment(context);
                return db.HtmlResult.DocumentElement.ChildNodes;
            }

            return db.HtmlResult.ChildNodes;
        }
Example #14
0
 public override Node ReplaceChild(Node newChild, Node oldChild)
 {
     throw new DOMException(ErrorCode.HierarchyRequestError);
 }
Example #15
0
        public virtual Node InsertBefore(Node newElement, Node referenceElement)
        {
            if (newElement is Attr || newElement is Document || newElement.Contains(this))
                throw new DOMException(ErrorCode.HierarchyRequestError);

            var n = _children.Length;

            for (int i = 0; i < n; i++)
            {
                if (_children[i] == referenceElement)
                    return InsertChild(i, newElement);
            }

            return AppendChild(newElement);
        }
Example #16
0
 public void SetEnd(Node refNode, int offset)
 {
     throw new NotImplementedException();
 }
Example #17
0
        public virtual Node InsertChild(Int32 index, Node child)
        {
            if (child is DocumentFragment)
            {
                var childs = child.ChildNodes;

                for (int i = 0; i < childs.Length; i++)
                    InsertChild(index + i, childs[i]);
            }
            else if (child is Attr || child is Document || child.Contains(this))
            {
                throw new DOMException(ErrorCode.HierarchyRequestError);
            }
            else
            {
                if (child.ParentNode != null)
                    throw new DOMException(ErrorCode.InUse);

                child._parent = this;
                child.OwnerDocument = _owner ?? (this as Document);
                _children.Insert(index, child);
            }

            return child;
        }
Example #18
0
 public void SetEndBefore(Node refNode)
 {
     throw new NotImplementedException();
 }
Example #19
0
        public virtual Node RemoveChild(Node child)
        {
            if (_children.Contains(child))
            {
                child._parent = null;
                _children.Remove(child);
            }

            return child;
        }
Example #20
0
 public void SetEndAfter(Node refNode)
 {
     throw new NotImplementedException();
 }
Example #21
0
        /// <summary>
        /// Finds the index of the given node.
        /// </summary>
        /// <param name="node">The node which needs to know its index.</param>
        /// <returns>The index of the node or -1 if the node is not a child.</returns>
        internal Int32 IndexOf(Node node)
        {
            var n = _children.Length;

            for (var i = 0; i < n; i++)
            {
                if (_children[i] == node)
                    return i;
            }

            return -1;
        }
Example #22
0
 public void SelectNodeContents(Node refNode)
 {
     throw new NotImplementedException();
 }
Example #23
0
        /// <summary>
        /// Runs the mutation macro as defined in 5.2.2 Mutation methods
        /// of http://www.w3.org/TR/domcore/.
        /// </summary>
        /// <param name="nodes">The nodes array to add.</param>
        /// <returns>A (single) node.</returns>
        protected Node MutationMacro(Node[] nodes)
        {
            if (nodes.Length > 1)
            {
                var node = new DocumentFragment();

                for (int i = 0; i < nodes.Length; i++)
                    node.AppendChild(nodes[i]);

                return node;
            }

            return nodes[0];
        }
Example #24
0
 public virtual Node CloneNode(Boolean deep = true)
 {
     var node = new Node();
     CopyProperties(this, node, deep);
     return node;
 }
 public override Node InsertBefore(Node newElement, Node referenceElement)
 {
     throw new DOMException(ErrorCode.NotSupported);
 }
Example #26
0
        public virtual DocumentPosition CompareDocumentPosition(Node otherNode)
        {
            if (this == otherNode)
                return DocumentPosition.Same;

            if(this.OwnerDocument != otherNode.OwnerDocument)
            {
                return DocumentPosition.Disconnected | DocumentPosition.ImplementationSpecific |
                    (otherNode.GetHashCode() > this.GetHashCode() ? DocumentPosition.Following : DocumentPosition.Preceding);
            }
            else if (this.Contains(otherNode))
            {
                return DocumentPosition.ContainedBy | DocumentPosition.Following;
            }
            else if (otherNode.Contains(this))
            {
                return DocumentPosition.Contains | DocumentPosition.Preceding;
            }

            return CompareRelativePositionInNodeList(_owner.ChildNodes, this, otherNode);
        }
 public override Node ReplaceChild(Node newChild, Node oldChild)
 {
     throw new DOMException(ErrorCode.NotSupported);
 }
Example #28
0
        public virtual Boolean Contains(Node otherNode)
        {
            if (otherNode == this)
                return true;

            for (int i = 0; i < _children.Length; i++)
            {
                if (_children[i] == otherNode)
                    return true;
                else if (_children[i].Contains(otherNode))
                    return true;
            }

            return false;
        }
Example #29
0
        /// <summary>
        /// Builds a list of nodes according with 8.4 Parsing HTML fragments.
        /// </summary>
        /// <param name="sourceCode">The string to use as source code.</param>
        /// <param name="context">[Optional] The context node to use.</param>
        /// <param name="options">[Optional] Options to use for the document generation.</param>
        /// <returns>A list of parsed nodes.</returns>
        public static NodeList HtmlFragment(String sourceCode, Node context = null, DocumentOptions options = null)
        {
            var source = new SourceManager(sourceCode);
            var doc = new HTMLDocument();

            //Disable scripting for HTML fragments (security reasons)
            options = options ?? new DocumentOptions(scripting: false);

            var db = new DocumentBuilder(source, doc, options);

            if (context != null)
            {
                if (context.OwnerDocument != null && context.OwnerDocument.QuirksMode != QuirksMode.Off)
                    doc.QuirksMode = context.OwnerDocument.QuirksMode;

                var parser = (HtmlParser)db.parser;
                parser.SwitchToFragment(context);
                return parser.Result.DocumentElement.ChildNodes;
            }

            return db.HtmlResult.ChildNodes;
        }
Example #30
0
        public override Boolean IsEqualNode(Node otherNode)
        {
            if (otherNode is Attr)
            {
                var a = this;
                var b = (Attr)otherNode;

                if (a._name == b._name && a._ns == b._ns && a._value == b._value)
                    return true;
            }

            return false;
        }