예제 #1
0
        static IEnumerable <DomNode> ExtractNodes(DomDocument doc, string text)
        {
            int    previousIndex = 0;
            string outText;
            var    matches = MatchVariables(text);

            foreach (Match match in matches)
            {
                outText = text.Substring(previousIndex, match.Index - previousIndex);
                if (outText.Length > 0)
                {
                    yield return(doc.CreateText(outText));
                }

                var expText = match.Groups["Expression"].Value;
                var e       = ParseAndBindExpr(expText);

                yield return(new HxlValueElement {
                    Expression = e
                });

                previousIndex = match.Index + match.Length;
            }

            outText = text.Substring(previousIndex, text.Length - previousIndex);

            if (outText.Length > 0)
            {
                yield return(doc.CreateText(outText));
            }
        }
        public void NodePosition_should_update_with_insert(bool useLinkedList)
        {
            DomDocument doc  = new DomDocument(useLinkedList);
            var         head = doc.CreateElement("head");

            doc.ChildNodes.Add(doc.CreateText(" "));
            doc.ChildNodes.Add(doc.CreateText(" "));
            doc.ChildNodes.Insert(0, head);

            Assert.Equal(0, head.NodePosition);
        }
예제 #3
0
        public void NodeValue_equals_text()
        {
            DomDocument doc = new DomDocument();
            var         pi  = doc.CreateText("hello");

            Assert.Equal("hello", pi.NodeValue);
        }
예제 #4
0
        public void NodeName_equals_special_name()
        {
            DomDocument doc = new DomDocument();
            var         pi  = doc.CreateText("hello");

            Assert.Equal("#text", pi.NodeName);
        }
예제 #5
0
        public void Clone_will_clone_annotations_copied_to_new_node()
        {
            var doc = new DomDocument();

            var node  = doc.CreateText("a").AddAnnotation(new object());
            var clone = node.Clone();

            Assert.HasCount(1, clone.AnnotationList.OfType <object>());
        }
        public void IndexOf_should_obtain_index_nominal(bool useLinkedList)
        {
            DomDocument doc = new DomDocument(useLinkedList);
            var         a   = doc.CreateElement("a");
            var         b   = doc.CreateText("  ");

            doc.ChildNodes.Add(a);
            doc.ChildNodes.Add(b);

            Assert.Equal(0, doc.ChildNodes.IndexOf(a));
            Assert.Equal(1, doc.ChildNodes.IndexOf(b));
        }
        public void construct_generic_dom_document_factory_methods()
        {
            DomDocument d = new DomDocument();
            var html = d.CreateElement("html");
            var body = d.CreateElement("body");
            var p = d.CreateElement("p");
            var text = d.CreateText("Hello, World");

            p.Append(text);

            d.Append(html);
            body.Append(p).AppendTo(html);
        }
        public void Add_should_move_extant_child_to_end(bool useLinkedList)
        {
            DomDocument doc  = new DomDocument(useLinkedList);
            var         head = doc.CreateElement("head");
            var         body = doc.CreateText(" ");

            doc.ChildNodes.Add(head);
            doc.ChildNodes.Add(body);
            doc.ChildNodes.Add(head);

            Assert.HasCount(2, doc.ChildNodes);
            Assert.Equal("head", doc.ChildNodes[1].NodeName);
        }
        public void GetEnumerator_should_enumerate_first_and_second(bool useLinkedList)
        {
            DomDocument doc = new DomDocument(useLinkedList);
            var         a   = doc.CreateElement("a");
            var         b   = doc.CreateText("  ");

            doc.ChildNodes.Add(a);
            doc.ChildNodes.Add(b);

            Assert.Equal(2, doc.ChildNodes.Count);
            Assert.Same(a, doc.ChildNodes.First());
            Assert.Same(b, doc.ChildNodes.Skip(1).First());
        }
        public void Add_should_add_to_end_multiple_times(bool useLinkedList)
        {
            DomDocument doc = new DomDocument(useLinkedList);

            var a = doc.CreateElement("a");
            var b = doc.CreateText("  ");

            doc.ChildNodes.Add(a);
            doc.ChildNodes.Add(b);

            Assert.Equal(2, doc.ChildNodes.Count);
            Assert.Same(a, doc.ChildNodes[0]);
            Assert.Same(b, doc.ChildNodes[1]);
        }
        public void construct_generic_dom_document_processing_factory()
        {
            DomDocument d = new DomDocument();
            var xml = d.CreateProcessingInstruction("xml");
            xml.AppendData("version=\"1.0\" standalone=\"yes\"");
            var html = d.CreateElement("html");
            var body = d.CreateElement("body");
            var p = d.CreateElement("p");
            var text = d.CreateText("Hello, World");

            p.Append(text);

            d.Append(html);
            body.Append(p).AppendTo(html);
        }