xquery using dataset and bind to gridview

Posted by Klbaiju under XML on 12/1/2010 | Points: 10 | Views : 2619 | Status : [Member] | Replies : 1
Hi, following is my xml file

<bookstore>

<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>

<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

i want to display the books with price > 30

how it is possible using xquery

I tried this
string strXmlBooks = Server.MapPath("Books.xml");

string strXquery = "<root>{for $x in doc("books.xml")/bookstore/book where $x/price>30 Return $x/title}</root>";

i want to connect the query to a dataset and finally bind to gridview

how it is possible

Regards
K L BAIJU




Responses

Posted by: T.saravanan on: 12/1/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi K L Baiju,

My suggestion is just read the XML file into DataSet then to filter your condition in that DataSet.Finally bind that filter value into GridView.
Its a simple way..

For your reference...


string sFile = "C:\\MyFile.xml";
DataSet ds = new DataSet();
ds.ReadXml(sFile);
// Row Filter
DataTable dtData = ds.Tables[0].Clone();
DataRow[ ] drRow = ds.Tables[0].Select("Price > 30 ");
if(drRow.Length > 0)
{
dtData = drRow.CopyToDataTable();
}
else
{
dtData = null;
}


Note: Check the DataType of that column may be its in string format.
Try this code...

For your Reference : http://csharp.net-informations.com/xml/filter-in-xml-file.htm

Cheers :)



Thanks,
T.Saravanan

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response