I currently have an XML, and wish to search that XML based on criteria, so for example find the child node <Title> where ID = 3, the XML set up can be seen below. Can anybody point me in the right direction please? I can search through the xml file but
i dont know how to use a criteria search.
System.Xml.Linq.XDocument contacts =System.Xml.Linq.XDocument.Load(DocumentPath) ;
var q = from c in contacts.Descendants("task")
where c.Element("ID").Value == "3"
select (string)c.Element("Title");
annoscia
Member
22 Points
75 Posts
Searching an XML file
Jan 24, 2013 02:03 PM|LINK
Hi All,
I currently have an XML, and wish to search that XML based on criteria, so for example find the child node <Title> where ID = 3, the XML set up can be seen below. Can anybody point me in the right direction please? I can search through the xml file but i dont know how to use a criteria search.
<?xml version="1.0" encoding="utf-8" ?> <project> <task> <ID>1</ID> <Title>Task 1</Title> <Start>04/01/2013</Start> <End>07/01/2013</End> </task> <task> <ID>2</ID> <Title>Task 2</Title> <Start>04/01/2013</Start> <End>07/01/2013</End> </task> <task> <ID>3</ID> <Title>Task 3</Title> <Start>04/01/2013</Start> <End>07/01/2013</End> </task> <task> <ID>4</ID> <Title>Task 4</Title> <Start>04/01/2013</Start> <End>07/01/2013</End> </task> </project>shanmugamm
Participant
1612 Points
317 Posts
Re: Searching an XML file
Jan 24, 2013 02:18 PM|LINK
Check this links
http://dotnet.dzone.com/articles/using-linq-xml-query-xml-data
http://stackoverflow.com/questions/2202004/how-to-search-xml-using-linq-to-xml-query
http://shanmugam-netguru.blogspot.com
Follow me in Linkedin
alankarp
Contributor
2042 Points
345 Posts
Re: Searching an XML file
Jan 24, 2013 02:52 PM|LINK
try below code
System.Xml.Linq.XDocument contacts =System.Xml.Linq.XDocument.Load(DocumentPath) ; var q = from c in contacts.Descendants("task") where c.Element("ID").Value == "3" select (string)c.Element("Title");Profile