XML file using LINQ
Can any onle help how to write code to read and print an element from an XML file using LINQ with simple example?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Nov 14, 2011, 2:12 AM EST
http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/reading-xml-file-through-linq-a-few-tips/
AartiRank #2,383 · 594 reputationPosted Nov 14, 2011, 2:24 AM EST
Plz check this one:
may be it will help you
static XDocument GetStarbuzzData()
{
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("Starbuzz Customer Loyalty Data"),
new XElement("starbuzzData",
new XAttribute("storeName", "Park Slope"),
new XAttribute("location", "Brooklyn, NY"),
new XElement("person",
new XElement("personalInfo",
new XElement("name", "Janet Venutian"),
new XElement("zip", 11215)),
new XElement("favoriteDrink", "Choco Macchiato"),
new XElement("moneySpent", 255),
new XElement("visits", 50)),
new XElement("person",
new XElement("personalInfo",
new XElement("name", "Liz Nelson"),
new XElement("zip", 11238)),
new XElement("favoriteDrink", "Double Cappuccino"),
new XElement("moneySpent", 150),
new XElement("visits", 35)),
new XElement("person",
new XElement("personalInfo",
new XElement("name", "Matt Franks"),
new XElement("zip", 11217)),
new XElement("favoriteDrink", "Zesty Lemon Chai"),
new XElement("moneySpent", 75),
new XElement("visits", 15)),
new XElement("person",
new XElement("personalInfo",
new XElement("name", "Joe Ng"),
new XElement("zip", 11217)),
new XElement("favoriteDrink", "Banana Split in a Cup"),
new XElement("moneySpent", 60),
new XElement("visits", 10)),
new XElement("person",
new XElement("personalInfo",
new XElement("name", "Sarah Kalter"),
new XElement("zip", 11215)),
new XElement("favoriteDrink", "Boring Coffee"),
new XElement("moneySpent", 110),
new XElement("visits", 15))));
return doc;
}