I need to query the xml which is in the below format;
<books>
<book>
<id>100</id>
<title>Microsoft SQL Server 2008 R2 Master Data Services</title>
<category>Information Technology</category>
<authors>
<author>Jeremy Kashel</author>
<author>Tim Kent</author>
<author>Martyn Bullerwell</author>
</authors>
<reviews>
<review>If you're looking for an excellent book on the new Master Data Services component of SQL Server 2008 R2, definitely check this one out! To be released in June 2011 by Packt Publishing!</review>
</reviews>
</book>
<book>
<id>101</id>
<title>Inside Microsoft SQL Server 2008: T-SQL Querying</title>
<category>Information Technology</category>
<authors>
<author>Itzik Ben-gan</author>
<author>Lubor Kollar</author>
<author>Dejan Sarka</author>
<author>Steve Kass</author>
</authors>
<reviews>
<review>Every "Inside SQL Server" book can be recommended, especially when written by Itzik!</review>
</reviews>
</book>
<book>
<id>103</id>
<title>The Lord of the Rings</title>
<category>Fantasy</category>
<authors>
<author>J.R.R. Tolkien</author>
</authors>
<reviews>
<review>Like fantasy? What are you waiting for then? It's a classic!</review>
<review>If you liked the movie, you'll love the book.</review>
</reviews>
</book>
</books>
Now i need to query the XML inorder to get all the book elements if ID = 100
Member
15 Points
62 Posts
XML query
Apr 18, 2013 08:27 AM|psm_8210|LINK
Hello All,
I need to query the xml which is in the below format;
<books>
<book>
<id>100</id>
<title>Microsoft SQL Server 2008 R2 Master Data Services</title>
<category>Information Technology</category>
<authors>
<author>Jeremy Kashel</author>
<author>Tim Kent</author>
<author>Martyn Bullerwell</author>
</authors>
<reviews>
<review>If you're looking for an excellent book on the new Master Data Services component of SQL Server 2008 R2, definitely check this one out! To be released in June 2011 by Packt Publishing!</review>
</reviews>
</book>
<book>
<id>101</id>
<title>Inside Microsoft SQL Server 2008: T-SQL Querying</title>
<category>Information Technology</category>
<authors>
<author>Itzik Ben-gan</author>
<author>Lubor Kollar</author>
<author>Dejan Sarka</author>
<author>Steve Kass</author>
</authors>
<reviews>
<review>Every "Inside SQL Server" book can be recommended, especially when written by Itzik!</review>
</reviews>
</book>
<book>
<id>103</id>
<title>The Lord of the Rings</title>
<category>Fantasy</category>
<authors>
<author>J.R.R. Tolkien</author>
</authors>
<reviews>
<review>Like fantasy? What are you waiting for then? It's a classic!</review>
<review>If you liked the movie, you'll love the book.</review>
</reviews>
</book>
</books>
Now i need to query the XML inorder to get all the book elements if ID = 100
i.e
For Id = 100, I need to get the author list
Please let me know if this can be done using c#
Contributor
2770 Points
774 Posts
Re: XML query
Apr 18, 2013 08:31 AM|dhol.gaurav|LINK
Hi
Check below function for the getting author list
let me know if any query
Gaurav Dhol
Skype ID : dhol.gaurav
Member
15 Points
62 Posts
Re: XML query
Apr 18, 2013 08:32 AM|psm_8210|LINK
Hi Gaurav,
Is this using jquery? I need to use c#
Contributor
2770 Points
774 Posts
Re: XML query
Apr 18, 2013 08:37 AM|dhol.gaurav|LINK
yes this is j query check following code for c#
path of selecting node is case sensitive please verify and update as per your requrement
let me know if any query
Gaurav Dhol
Skype ID : dhol.gaurav
Contributor
4207 Points
1154 Posts
Re: XML query
Apr 18, 2013 08:42 AM|mm10|LINK
To get all book elements with ID = 100, use XPathDocument:
Member
15 Points
62 Posts
Re: XML query
Apr 18, 2013 08:55 AM|psm_8210|LINK
thanks for the reply, this has resolved my query.