public void RT1() { var doc = new XmlDocument(); doc.Begin("bookstore") .Add("locations") .Add("location", new { store_id = "1", address = "21 Jump St", phone = "123456"}).Up() .Add("location", new { store_id = "2", address = "342 Pitt St", phone = "9876543"}).Up() .Up() .Add("books") .Add("book", new {title = "The Enchiridion", price = "9.75"}) .Add("author", "Epictetus").Up() .Add("stores_with_stock") .Add("store", new { store_id = "1"}).Up() .Up() .Up() .Add("book", new {title = "Signal to Noise", price = "5.82"}) .Add("author", "Neil Gaiman").Up() .Add("author", "Dave McKean").Up() .Add("stores_with_stock") .Add("store", new { store_id = "1"}).Up() .Add("store", new { store_id = "2"}).Up() .Up() .Up() .Up() .Add("staff") .Add("member", new { firstname = "Ben", lastname = "Hughes", staff_id = "123"}).Up() .Add("member", new { firstname = "Freddie", lastname = "Smith", staff_id = "124"}).Up(); Assert.AreEqual(Resource.BookstoreExpectedNotPretty, doc.ToString()); Assert.AreEqual(Resource.BookstoreExpectedPretty, doc.ToString(true)); var xmlDoc = new System.Xml.XmlDocument(); Assert.DoesNotThrow(() => xmlDoc.LoadXml(doc.ToString())); }
public void MyTest() { var doc = new XmlDocument(); doc.Begin("organisation") .Add("staff") .Add("member", new { name = "Joe Smith", age = "45" }).Up() .Add("member", new { name = "Jane Smith", age = "48" }).Up() .Up() .Add("offices") .Add("office", new { name = "Head Office", location = "Balmain, Sydney" }).Up() .Up() .Add("revenue", "0").Up() .Add("description").CData("This organisation is a world class leader in excellence").Up() .Add("investors"); Console.WriteLine(doc.ToString(true)); // enable pretty formatting }
public XmlDocument GenerateXML() { var doc = new XmlDocument(); var rss = doc.Begin("rss"); rss.Attributes = new Dictionary<string, string>() { {"version", "2.0"}, {"xmlns:content", "http://purl.org/rss/1.0/modules/content/"}, {"xmlns:wfw", "http://wellformedweb.org/CommentAPI/"}, {"xmlns:dc", "http://purl.org/dc/elements/1.1/"}, {"xmlns:wp", "http://wordpress.org/export/1.2/"}, {"xmlns:excerpt", "http://wordpress.org/export/1.2/excerpt/"} }; var channel = rss.Add("channel"); channel.Add("title", Title).Up() .Add("link", Link).Up() .Add("description").CData(Description).Up() .Add("language", "en").Up() .Add("wp:wxr_version", "1.1").Up() .Add("generator", "hughesoft.com").Up() .Add("pubDate", PubDate.ToString()).Up() .Add("wp:base_site_url", BaseUrl).Up() .Add("wp:base_blog_url", BlogUrl); foreach (var tag in Posts.SelectMany(x => x.Tags)) channel.Add("wp:tag") .Add("wp:tag_slug", tag.Slug).Up() .Add("wp:tag_name").CData(tag.Name); foreach (var cat in Posts.SelectMany(x => x.Categories)) channel.Add("wp:category") .Add("wp:category_nicename", cat.NiceName).Up() .Add("wp:cat_name").CData(cat.Name).Up() .Add("wp:category_parent", cat.Parent); foreach (var post in Posts) channel.Children.Add(post.GenerateXML()); return doc; }
public void NullValuesAreHandled() { var doc = new XmlDocument(); Assert.DoesNotThrow(() => doc.Begin("x").Add("guy", null)); }