Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string location = "Oslo";
- var training = (from item in doc.Descendants("item")
- where item.Value.Contains(location)
- select new
- {
- event = item.Element("event").Value,
- event_location = item.Element("location").Value
- }).ToList();
- <training>
- <item>
- <event>C# Training</event>
- <location>Prague</location>
- <location>Oslo</location>
- <location>Amsterdam</location>
- <location>Athens</location>
- <location>Dublin</location>
- <location>Helsinki</location>
- </item>
- <item>
- <event>LINQ Training</event>
- <location>Bucharest</location>
- <location>Oslo</location>
- <location>Amsterdam</location>
- <location>Helsinki</location>
- <location>Brussels</location>
- <location>Dublin</location>
- </item>
- </training>
- string location = "Oslo";
- var training = from loc in doc.Descendants("location")
- where loc.Value == location
- select new
- {
- event = loc.Parent.Element("event").Value,
- event_location = loc.Value
- };
- string location = "Oslo";
- var training = from loc in doc.Descendants("location")
- where loc.Value == location
- select new
- {
- event = loc.Parent.Element("event").Value,
- event_locations = loc.Parent.Elements("location")
- .Select(e => e.Value)
- };
- for (var entry in training)
- {
- Console.WriteLine("Event: {0}; Locations: {1}",
- entry.event,
- string.Join(", ", entry.event_locations.ToArray());
- }
- var training = (from item in root.Descendants("item")
- where item.Value.Contains(location)
- select new
- {
- name = item.Element("event").Value,
- location = (from node in item.Descendants("location")
- where node.Value.Equals(location)
- select node.Value).FirstOrDefault(),
- }).ToList();
Add Comment
Please, Sign In to add comment