Skip to content

Instantly share code, notes, and snippets.

@cowlike
Last active September 30, 2015 05:07
Show Gist options
  • Save cowlike/1726151 to your computer and use it in GitHub Desktop.
Save cowlike/1726151 to your computer and use it in GitHub Desktop.
from: www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("Sample RSS Feed"),
new XElement("rss",
new XAttribute("version", "2.0"),
new XElement ("channel",
new XElement("title", "RSS Channel Title"),
new XElement("description", "RSS Channel Description."),
new XElement("link", "http://aspiring-technology.com"),
new XElement("item",
new XElement("title", "First article title"),
new XElement("description", "First Article Description"),
new XElement("pubDate", DateTime.Now.ToUniversalTime()),
new XElement("guid", Guid.NewGuid())),
new XElement("item",
new XElement("title", "Second article title"),
new XElement("description", "Second Article Description"),
new XElement("pubDate", DateTime.Now.ToUniversalTime()),
new XElement("guid", Guid.NewGuid()))
)
)
);
XElement xml = new XElement("contacts",
from c in db.Contacts
orderby c.ContactId
select new XElement("contact",
new XAttribute("contactId", c.ContactId),
new XElement("firstName", c.FirstName),
new XElement("lastName", c.LastName))
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment