public void OuterXml_should_be_equal_to_xml() { var d = new DomDocument(); const string xml = "<html> <head> </head> <body a=\"false\"> </body> </html>"; d.LoadXml(xml); Assert.Equal(xml, d.OuterXml); }
/// <summary> /// 将RTF文档内容填充到文本文档中 /// </summary> /// <param name="document">文本文档对象</param> public void FillTo(DomDocument document) { document.Clear(); ReadContent(document); //document.FixElements(); }
public void Attributes_null_and_no_values() { DomDocument doc = new DomDocument(); Assert.Null(doc.Attributes); Assert.Same(doc, doc.Attribute("s", "s")); Assert.Null(doc.Attribute("s")); }
public void InnerText_set_will_replace_inner_element_with_text() { var doc = new DomDocument(); doc.LoadXml("<!-- comment--><hello></hello>"); doc.InnerText = "world"; Assert.Equal("<!-- comment--><hello>world</hello>", doc.OuterXml); }
public void CreateElement_implies_owner_document() { DomDocument doc = new DomDocument(); var html = doc.CreateElement("html"); Assert.Null(html.ParentNode); Assert.Same(doc, html.OwnerDocument); }
public void test_created_node_not_in_document_has_owner() { DomDocument doc = new DomDocument(); var pi = doc.CreateProcessingInstruction("hello", "world"); Assert.That(pi.ParentNode, Is.Null); Assert.That(pi.ParentElement, Is.Null); Assert.That(pi.OwnerDocument, Is.EqualTo(doc)); }
public void Prepend_should_apply_correct_order_two() { var doc = new DomDocument(); var element = doc.AppendElement("html"); element.Prepend(doc.CreateElement("head"), doc.CreateElement("body")); Assert.Equal("head", doc.DocumentElement.Elements[0].LocalName); Assert.Equal("body", doc.DocumentElement.Elements[1].LocalName); }
static DomAttribute Attribute(string text) { var doc = new DomDocument(); var attr = doc.CreateAttribute("hello"); attr.Value = text; return(attr); }
/// <summary> /// Parses <paramref name="text"/> and produces <see cref="DomDocument"/>. /// </summary> /// <param name="text"></param> /// <returns></returns> public virtual DomDocument Parse(string text) { DomDocument document = new DomDocument(); ParseBlockElements(document, text); return(document); }
public void LoadXml_from_xml_should_roundtrip() { var doc = new DomDocument(); var xml = "<html> <body a=\"true\" b=\"false\"> Text <p a=\"b\" /> <span> <time /> </span> </body> </html>"; doc.LoadXml(xml); Assert.Equal(xml, doc.ToXmlString()); }
public void ParentElement_should_be_null_for_root() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var body = html.AppendElement("body"); Assert.Null(html.ParentElement); }
public void NextSibling_should_process_single_child() { DomDocument doc = new DomDocument(); var svg = doc.AppendElement("svg"); var g1 = svg.AppendElement("g"); Assert.Null(g1.NextSibling); }
public void Create_any_node_will_add_it_unlinked(object o) { Func <DomDocument, DomObject> action = (Func <DomDocument, DomObject>)o; var doc = new DomDocument(); var node = action(doc); Assert.Same(doc, node.OwnerDocument); }
public void Clone_should_unparent() { DomDocument doc = new DomDocument(); var e = doc.AppendElement("t"); Assert.Same(doc, e.ParentNode); Assert.Null(e.Clone().ParentNode); }
public void NameContext_should_copy_on_clone() { var doc = new DomDocument(); var e = doc.AppendElement("e"); e.NameContext = DomNameContext.Html; Assert.Same(DomNameContext.Html, e.SetName("xx").NameContext); Assert.Same(DomNameContext.Html, e.Clone().NameContext); }
public void AncestorNodes_should_provide_expected_access() { DomDocument doc = new DomDocument(); var e = doc.AppendElement("a").AppendElement("b").AppendElement("c").AppendElement("d"); Assert.HasCount(4, e.AncestorNodes); Assert.Equal("c", e.AncestorNodes[0].LocalName); Assert.Equal("a", e.AncestorNodes[2].LocalName); Assert.Equal("#document", e.AncestorNodes.Last().LocalName); }
public void Prepend_should_apply_to_null() { DomDocument doc = new DomDocument(); Assert.DoesNotThrow(() => doc.Prepend((DomNode) null)); Assert.Same(doc, doc.Prepend((DomNode) null)); Assert.DoesNotThrow(() => doc.Prepend((IEnumerable<DomNode>) null)); Assert.Same(doc, doc.Prepend((IEnumerable<DomNode>) null)); }
public void NameContext_inherits_from_owner_document() { var doc = new DomDocument(); doc.NameContext = DomNameContext.Html; var e = doc.AppendElement("e"); var f = e.AppendElement("ff"); Assert.Same(DomNameContext.Html, f.NameContext); }
public void Prepend_should_apply_correct_order_enumeration() { var doc = new DomDocument(); var element = doc.AppendElement("html"); var items = Enumerable.Range(1, 6).Select(t => doc.CreateElement("x" + t)); element.Prepend(items); Assert.Equal("x1 x2 x3 x4 x5 x6", string.Join(" ", doc.DocumentElement.Elements.Select(t => t.Name))); }
public void InnerXml_should_parse_from_and_rebuild_nodes() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); html.InnerXml = "<head> <title /> </head> <body c=\"f\"> </body>"; Assert.Equal("<html><head> <title /> </head> <body c=\"f\"> </body></html>", doc.ToXmlString()); }
public void test_create_attribute_unlinked_implies_owner_document() { DomDocument doc = new DomDocument(); var html = doc.CreateAttribute("class"); Assert.That(html.OwnerElement, Is.Null); Assert.That(html.ParentNode, Is.Null); Assert.That(html.OwnerDocument, Is.SameAs(doc)); }
public void construct_generic_dom_document_fluent_appenders() { DomDocument d = new DomDocument(); d.AppendElement("html") .AppendElement("body") .AppendElement("p") .AppendText("Hello, World"); }
public void test_attributes_null_and_no_values() { DomDocument doc = new DomDocument(); Assert.That(doc.Attributes, Is.Null); // TODO Review this behavior: should it be an error? Assert.That(doc.Attribute("s", "s"), Is.Null); }
public void Append_to_element_should_add_attribute() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var attr = doc.CreateAttribute("lang"); html.Append(attr); Assert.Equal(1, html.Attributes.Count); }
public void test_add_annotation_nominal() { DomDocument d = new DomDocument(); d.AddAnnotation(DBNull.Value); Assert.True(d.HasAnnotation<DBNull>()); Assert.That(d.Annotations<DBNull>(), Is.Not.Empty); Assert.That(d.Annotations<Uri>(), Is.Empty); Assert.That(d.Annotation<DBNull>(), Is.EqualTo(DBNull.Value)); }
public void test_append_element_implies_parent() { DomDocument doc = new DomDocument(); var ele = doc.AppendElement("html"); Assert.That(ele.ParentNode, Is.SameAs(doc)); Assert.That(doc.DocumentElement, Is.SameAs(ele)); Assert.That(doc.DocumentElement.ChildNodes, Is.Empty); Assert.False(doc.UnlinkedNodes.Contains(ele)); }
public void RemoveAnnotation_will_detach_node() { var doc = new DomDocument(); var anno = new FLifecycleAnnotation(); doc.CreateElement("a").RemoveAnnotation(anno); Assert.Equal(1, anno.DetachingCallCount); }
// INTERNAL CONSTRUCTORS //////////////////////////////////////////// #region Constructors internal ToManyIncludedResourcesBuilder(DocumentBuilder parentBuilder, DomDocument domDocument, IToManyIncludedResources <TFromResource, TToResource> toManyIncludedResources) : base(parentBuilder, domDocument.GetOrAddIncluded(), toManyIncludedResources.ToResourceCollection) { Contract.Requires(toManyIncludedResources != null); this.Builder = this; this.AddResourceLinkage(toManyIncludedResources); }
protected override void VisitDocument(DomDocument document) { if (document == null) throw new ArgumentNullException("document"); writer.WriteStartDocument(); Visit(document.ChildNodes); writer.WriteEndDocument(); }
public void TextContent_gets_and_sets_text() { DomDocument doc = new DomDocument(); var attr = doc.CreateAttribute("s"); attr.TextContent = "text"; Assert.Equal("text", attr.TextContent); }
public void AppendAttribute_implies_parent_and_owner() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var attr = html.AppendAttribute("lang", "en"); Assert.Same(doc, attr.OwnerDocument); Assert.Same(html, attr.OwnerElement); }
// PUBLIC CONSTRUCTORS ////////////////////////////////////////////// #region Constructors public DocumentReader(Document apiDocument, IServiceModel serviceModel) { Contract.Requires(serviceModel != null); Contract.Requires(apiDocument != null); var domDocument = DomDocument.Parse(apiDocument, serviceModel); this.DomDocument = domDocument; }
public void CreateProcessingInstruction_node_not_in_document_has_owner() { DomDocument doc = new DomDocument(); var pi = doc.CreateProcessingInstruction("hello", "world"); Assert.Null(pi.ParentNode); Assert.Null(pi.ParentElement); Assert.Equal(doc, pi.OwnerDocument); }
// INTERNAL CONSTRUCTORS //////////////////////////////////////////// #region Constructors internal ToOneIncludedResourceBuilder(DocumentBuilder parentBuilder, DomDocument domDocument, IToOneIncludedResource <TFromResource, TToResource> toOneIncludedResource) : base(parentBuilder, domDocument.GetOrAddIncluded(), toOneIncludedResource.ToResource) { Contract.Requires(toOneIncludedResource != null); this.Builder = this; this.AddResourceLinkage(toOneIncludedResource); }
public void test_add_child_document_element_implies_parent_and_owner() { DomDocument doc = new DomDocument(); var html = doc.AppendText("leading ws"); Assert.That(html.ChildNodes.Count, Is.EqualTo(0)); Assert.That(html.OwnerDocument, Is.SameAs(doc)); Assert.That(html.ParentNode, Is.SameAs(doc)); Assert.That(html.ParentElement, Is.Null); }
public void Text_for_List_DomValue_will_separate_tokens() { var attr = new DomDocument().CreateAttribute("h"); attr.SetValue(new List <string> { "hello", "world" }); Assert.Equal("hello world", attr.Value); }
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 Minimal_includes_element_position_when_it_is_ambiguous_for_DomElement_GetDomPath() { var a = new DomDocument().AppendElement("a"); var dd = a.AppendElement("b"); a.AppendElement("b"); Assert.Equal("/a/b[0]", dd.GetDomPath(DomPathGenerator.Minimal).ToString()); }
public void test_create_attribute_implies_owner_document() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var attr = doc.CreateAttribute("class"); html.Attributes.Add(attr); Assert.That(attr.OwnerElement, Is.SameAs(html)); Assert.That(attr.ParentNode, Is.Null); Assert.That(attr.OwnerDocument, Is.SameAs(doc)); }
public void test_append_multiple_noncontent_nodes() { DomDocument doc = new DomDocument(); var docType = doc.CreateDocumentType("html"); var ws = doc.CreateComment("time"); var html = doc.CreateElement("html"); doc.Append(docType, ws, html); Assert.That(doc.DocumentElement, Is.SameAs(html)); Assert.That(doc.ChildNodes.Count, Is.EqualTo(3)); }
public void test_add_child_implies_parent_and_owner() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var text = html.AppendText("ws"); Assert.That(text.ChildNodes.Count, Is.EqualTo(0)); Assert.That(text.OwnerDocument, Is.SameAs(doc)); Assert.That(text.ParentNode, Is.SameAs(html)); Assert.That(text.ParentElement, Is.SameAs(html)); }
public void test_append_attribute_implies_parent_and_owner() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var attr = html.AppendAttribute("lang", "en"); Assert.That(attr.OwnerDocument, Is.SameAs(doc)); Assert.That(attr.OwnerElement, Is.SameAs(html)); Assert.That(attr.ParentNode, Is.Null); // per spec }
public void test_basic_property_access() { DomDocument doc = new DomDocument(); string ws = "leading ws"; var html = doc.AppendText(ws); Assert.That(html.ToString(), Is.EqualTo(ws)); Assert.That(html.TextContent, Is.EqualTo(ws)); Assert.That(html.Data, Is.EqualTo(ws)); Assert.That(html.NodeValue, Is.EqualTo(ws)); }
public void test_append_attribute_implies_add() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var attr = doc.CreateAttribute("lang", "en"); html.Append(attr); Assert.That(html.Attributes.Count, Is.EqualTo(1)); Assert.That(html.Attribute("lang"), Is.EqualTo("en")); Assert.That(attr.OwnerDocument, Is.SameAs(doc)); }
public void test_outer_text_domelement() { DomDocument doc = new DomDocument(); var html = doc.AppendText("leading ws"); string htmlText = "leading ws"; Assert.That(html.OuterText, Is.EqualTo(htmlText)); Assert.That(html.ToString(), Is.EqualTo(htmlText)); Assert.That(doc.OuterText, Is.EqualTo(htmlText)); Assert.That(doc.ToString(), Is.EqualTo(htmlText)); }
public void test_add_attribute_implies_parent_and_owner() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); html.Attribute("lang", "en"); DomAttribute attr = html.Attributes[0]; Assert.That(attr.OwnerDocument, Is.SameAs(doc)); Assert.That(attr.OwnerElement, Is.SameAs(html)); Assert.That(attr.ParentNode, Is.Null); // per spec Assert.False(doc.UnlinkedNodes.Contains(attr)); }
public void test_attribute_adjacent_nominal() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); html.Attribute("lang", "en"); html.Attribute("dir", "ltr"); html.Attribute("data-e", "e"); DomAttribute attr = html.Attributes[1]; Assert.That(attr.NodePosition, Is.EqualTo(1)); Assert.That(attr.NextAttribute.Name, Is.EqualTo("data-e")); Assert.That(attr.PreviousAttribute.Name, Is.EqualTo("lang")); }
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 test_base_uri_inherited() { DomDocument doc = new DomDocument(); var html = doc.CreateElement("html"); var example = new Uri("https://example.com"); html.BaseUri = example; doc.Append(html); var body = doc.CreateElement("body"); html.Append(body); Assert.That(html.BaseUri, Is.EqualTo(example)); Assert.That(body.BaseUri, Is.EqualTo(example)); }
public void test_outer_text_domelement() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var body = html.AppendElement("body"); html.Attribute("lang", "en"); html.Attribute("data-cast", "true"); body.Attribute("dir", "ltr"); body.Attribute("class", "hl"); body.AppendText("Hello, world!"); string htmlText = "<html lang=\"en\" data-cast=\"true\"><body dir=\"ltr\" class=\"hl\">Hello, world!</body></html>"; Assert.That(html.OuterText, Is.EqualTo(htmlText)); Assert.That(html.ToString(), Is.EqualTo(htmlText)); }
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); }
private void CreateCourseDom() { var d = new DomDocument<Manifest>(); ADL.SCORM.Namespaces.LoadNamespaceMappings(d); pMessages = new UserMessageCollection(); if (d.Load(this.pMessages, this.pManifestFileInfo)) { this.pManifest = d.DocumentElement; } else { throw new ApplicationException("The imsmanifet that was selected could not be loaded."); } }
public void test_descendents_and_self() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var body = html.AppendElement("body"); var para1 = body.AppendElement("p"); var para2 = body.AppendElement("div"); para1.AppendText("Hello, world!"); para2.AppendText("Hello, world!"); Assert.That(string.Join(" ", html.DescendantsAndSelf.Select(t => t.NodeName)), Is.EquivalentTo("html body p div")); Assert.That(string.Join(" ", html.Descendants.Select(t => t.NodeName)), Is.EquivalentTo("body p div")); }
public void test_create_processing_instruction_nominal() { DomDocument doc = new DomDocument(); var pi = doc.CreateProcessingInstruction("hello", "world"); Assert.That(pi.TextContent, Is.EqualTo("world")); Assert.That(pi.Data, Is.EqualTo("world")); Assert.That(pi.Target, Is.EqualTo("hello")); Assert.That(pi.NodeValue, Is.EqualTo("world")); Assert.That(pi.Prefix, Is.Null); Assert.That(pi.LocalName, Is.Null); Assert.That(pi.NamespaceUri, Is.Null); Assert.That(pi.NodeName, Is.EqualTo("hello")); Assert.That(pi.ChildNodes.Count, Is.EqualTo(0)); Assert.That(pi.NodeType, Is.EqualTo((DomNodeType) 7)); }
public void test_elements_list_nominal() { DomDocument doc = new DomDocument(); var svg = doc.AppendElement("svg"); var g1 = svg.AppendElement("g"); var g2 = svg.AppendElement("g"); var g3 = svg.AppendElement("g"); Assert.That(svg.Elements[1], Is.SameAs(g2)); Assert.That(svg.Elements[2], Is.SameAs(g3)); Assert.That(svg.Element(1), Is.SameAs(g2)); Assert.That(svg.Element(2), Is.SameAs(g3)); Assert.That(svg.Element("g"), Is.SameAs(g1)); }
public void test_clear_collection_implies_no_parent() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var attr1 = html.AppendAttribute("lang", "en"); var attr2 = html.AppendAttribute("dir", "ltr"); var attr3 = html.AppendAttribute("class", "y"); Assert.That(attr1.OwnerDocument, Is.SameAs(doc)); Assert.That(attr1.OwnerElement, Is.SameAs(html)); Assert.That(attr1.ParentElement, Is.Null); // spec html.Attributes.Clear(); Assert.That(html.Attributes.Count, Is.EqualTo(0)); Assert.That(attr1.OwnerDocument, Is.SameAs(doc)); Assert.That(attr1.OwnerElement, Is.Null); // spec Assert.That(attr1.ParentElement, Is.Null); }
public void test_append_child_implies_parent() { DomDocument doc = new DomDocument(); var html = doc.CreateElement("html"); doc.Append(html); var body = doc.CreateElement("body"); html.Append(body); Assert.That(html.ParentNode, Is.SameAs(doc)); Assert.That(body.ParentNode, Is.SameAs(html)); Assert.That(html.ChildNode(0), Is.SameAs(body)); Assert.That(html.ChildNodes[0], Is.SameAs(body)); Assert.That(html.ChildNodes, Is.EquivalentTo(new[] { body })); Assert.That(html.ChildNodes.ToArray(), Is.EquivalentTo(new[] { body })); }
public void test_remove_from_collection_implies_no_parent() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var attr1 = html.AppendAttribute("lang", "en"); Assert.That(attr1.OwnerDocument, Is.SameAs(doc)); Assert.That(attr1.OwnerElement, Is.SameAs(html)); Assert.That(attr1.ParentElement, Is.Null); // spec Assert.That(attr1.NodePosition, Is.EqualTo(0)); Assert.That(html.Attributes.Count, Is.EqualTo(1)); Assert.That(html.Attributes.IndexOf(attr1), Is.EqualTo(0)); Assert.True(html.Attributes.Remove(attr1)); Assert.That(html.Attributes.Count, Is.EqualTo(0)); Assert.That(html.Attributes.IndexOf(attr1), Is.EqualTo(-1)); Assert.That(attr1.OwnerDocument, Is.SameAs(doc)); Assert.That(attr1.OwnerElement, Is.Null); // spec Assert.That(attr1.ParentElement, Is.Null); }
///// <summary> ///// Create a new CQ object from html ///// </summary> ///// <param name="text"></param> ///// <returns></returns> //public static implicit operator CQ(char[] html) //{ // return CQ.Create(html); //} ///// <summary> ///// Create a new CQ object from an element ///// </summary> ///// <param name="obj"></param> ///// <returns></returns> //public static implicit operator CQ(DomObject obj) //{ // return CQ.Create(obj); //} #endregion #region Internal DOM creation methods /// <summary> /// Bind this instance to a new empty DomDocument configured with the default options. /// </summary> protected void CreateNewDocument() { Document = new DomDocument(); }
public override void AwakeFromNib () { tblNotes.Source = new TableNotesDataSource (tblNotes, searchField, noteWebView); TableNotesDataSource.SelectedNoteChanged += delegate(Note note) { loadNote (note); }; KeyboardListener.NoteContentChanged += NoteContentChanged; loadNoteWebKit (); setTitle ("Tomboy"); noteWebView.OnFinishedLoading += delegate { installKeyboardHandler (); Console.WriteLine ("OnFinishedLoading"); }; noteWebView.FinishedLoad += delegate { document = noteWebView.MainFrameDocument; Console.WriteLine ("webView Finished loading"); }; this.Window.WillClose += delegate { Console.WriteLine ("Will Close"); }; }