public void Unwrap_returns_combined_list_of_child_nodes()
        {
            var doc = new DomDocument();

            doc.OuterXml = @"<root>
                                <p><a /><b /><c /></p>
                                <p></p>
                                <p><d /></p>
                                <p><e /></p>
                             </root>";
            var result = doc.QuerySelectorAll("p").Unwrap();
            var names  = doc.QuerySelector("root").Children.NodeNames();

            Assert.Equal(new [] { "a", "b", "c", "d", "e" }, names);
        }
 public void PrecedingNodes_should_obtain_inorder_preceding_nodes() {
     string xml = @"<root>
                       <m>
                        <a />
                        <b>
                         <c>
                           <d />
                         </c>
                        </b><e />
                    </m><f />
                    </root>";
     DomDocument doc = new DomDocument();
     doc.LoadXml(xml);
     var e = doc.QuerySelector("e");
     Assert.Equal("#document root #text m #text a #text b #text c #text #text d #text", string.Join(" ", e.PrecedingNodes.Select(t => t.NodeName)));
 }
Exemple #3
0
        public void Xmlns_should_update_name_on_ancestor_taking_name_context(string newOwner)
        {
            var doc = new DomDocument();

            doc.NameContext = DomNameContext.Xml;
            var element = doc.AppendElement("ancestor").AppendElement("parent").AppendElement("a:b");

            Assume.Equal("a:b", element.LocalName);

            doc.QuerySelector(newOwner).Attribute("xmlns:a", "namespace-a");

            // The name gets rewritten to use the namespace semantics
            Expect(element.NameContext).ToBe.InstanceOf(typeof(XmlNameContext));
            Expect(element.Name).ToBe.InstanceOf(typeof(DomName.QName));
            Expect(element.NamespaceUri).ToBe.EqualTo("namespace-a");
            Expect(element.LocalName).ToBe.EqualTo("b");
        }
Exemple #4
0
        public void Xmlns_should_update_name_on_taking_as_a_descendant_from_unlinked_ownership(string newOwner)
        {
            var doc = new DomDocument();

            doc.NameContext = DomNameContext.Xml;
            doc.AppendElement("ancestor").AppendElement("parent");
            doc.DocumentElement.Attribute("xmlns:a", "namespace-a");

            var orphan = doc.CreateElement("a:b");

            Assume.Equal("a:b", orphan.LocalName);

            doc.QuerySelector(newOwner).Append(orphan);

            // The name gets rewritten to use the namespace semantics
            Expect(orphan.LocalName).ToBe.EqualTo("b");
            Expect(orphan.NamespaceUri).ToBe.EqualTo("namespace-a");
        }
        public void ObserveAttributes_callback_should_be_invoked_on_removing_an_attribute(Action <DomElement> callback)
        {
            var doc = new DomDocument().LoadXml(@"
                <root attr='root value' />
            ".Replace("'", "\""));

            var element = doc.QuerySelector("root");

            var evts = new TestActionDispatcher <DomAttributeEvent>(_ => {});

            doc.ObserveAttributes(element, evts.Invoke);

            callback(element);

            Assert.Equal(1, evts.CallCount);
            Assert.Equal("root value", evts.ArgsForCall(0).OldValue);
            Assert.Null(evts.ArgsForCall(0).Value);
            Assert.Equal("attr", evts.ArgsForCall(0).LocalName);
        }