Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have an XML file that looks similar to this:
<doc>
  <item type="1">HelloWorld</item>
  <item type="2">LINQ</item>
  <item type="3">C#</item>
</doc>


I have an Item class with 3 string variables a,b & c and currently this is what I'm doing:

SQL
var Results = from docs in result.Descendants("doc")
              select new Item
              {
                 a = (from docs2 in docs.Descendants("item") 
                      where docs2.Attribute("type").Value == "1"
                      select docs2.Value).First(),
                 b = (from docs2 in docs.Descendants("item")
                      where docs2.Attribute("type").Value == "2"                      
                      select docs2.Value).First(),
                 c = (from docs2 in docs.Descendants("item")
                      where docs2.Attribute("type").Value == "3"
                      select docs2.Value).First()
              };


I'm unable to change the format of the XML file.
Is there a better way of doing this?
Posted

1 solution

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900