public void Append_generates_composite_write_output() { var html = new DomDocument().LoadXml(@" <a> <b a='100' /> <c> <b /> </c> </a>".Replace('\'', '"')); var w = html.QuerySelectorAll("b").Append(); w.WriteStartElement("new"); w.WriteStartAttribute("attr"); w.WriteValue("value"); w.WriteEndAttribute(); w.WriteEndElement(); w.WriteValue("significant text"); Assert.Equal(@" <a> <b a=""100""><new attr=""value""/>significant text</b> <c> <b><new attr=""value""/>significant text</b> </c> </a>".Replace('\'', '"'), html.OuterXml ); }
public void Wrap_with_fragment_should_remove_children_from_document() { var doc = new DomDocument(); doc.LoadXml(@"<html> <a /> <b /> <c /> </html>"); var frag = doc.CreateDocumentFragment(); doc.QuerySelectorAll("html > *").Wrap(frag); Assert.Equal("<html> </html>", doc.ToXmlString()); Assert.Equal("<a /><b /><c />", frag.ToXmlString()); }
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 ObserveAttributes_should_invoke_optimized_registration() { var doc = new DomDocument(); doc.AppendElement("hello").AppendElement("world"); var evts = new TestActionDispatcher <DomAttributeEvent>(_ => {}); var observer = doc.ObserveAttributes(doc.DocumentElement, "l", evts.Invoke, DomScope.TargetAndDescendants); doc.QuerySelectorAll("*").Attribute("l", "k"); Assert.Equal(2, evts.CallCount); Assert.Equal("hello", evts.ArgsForCall(0).Target.LocalName); Assert.Equal("world", evts.ArgsForCall(1).Target.LocalName); Assert.Equal("l", evts.ArgsForCall(1).LocalName); }
public void ImmediateParent_should_consider_depth() { DomDocument d = new DomDocument(); d.LoadXml(@"<html> <a id='1'> <a id='2'> <a id='3'> </a> </a> </a> </html>"); var match = d.QuerySelectorAll("html > a"); Assert.HasCount(1, match); Assert.Equal("1", match.First().Attribute("id")); }
public void Unwrap_should_unwrap_nodes() { const string xml = @"<section> <dl> <dd class='f'><dl></dl> </dd> <dd class='e'><dl></dl></dd> </dl> </section>"; var doc = new DomDocument(); doc.LoadXml(xml); doc.QuerySelectorAll("dl").QuerySelectorAll("> dd").Unwrap(); Assert.Equal("<section>\n<dl>\n<dl />\n<dl />\n</dl>\n</section>", doc.CompressWhitespace().ToXmlString()); }
public void Append_can_add_attributes_to_elements() { var html = new DomDocument().LoadXml(@" <a> <b a='100' /> <b /> </a>".Replace('\'', '"')); var w = html.QuerySelectorAll("b").Append(); w.WriteStartAttribute("a"); w.WriteValue("value"); w.WriteEndAttribute(); Assert.Equal(@" <a> <b a='100value'/> <b a='value'/> </a>".Replace('\'', '"'), html.OuterXml ); }