Recently in the blog Code During the reconstruction, I found that it is quite convenient to use able. Select to query XML data.
For example, we can query the data of the corresponding node in XML data based on the parameter values in the URL.
Suppose we have such an XML data file catalog. xml: < Navigation >
< Catalog Title = "Non-technical Zone" URL = "Default. aspx? Cate = 2" RSS = "Mainfeed. aspx? Cate = 2" Visible = "True" Cate = "2" />
< Catalog Title = "Reprinted area" URL = "Default. aspx? Cate = 7" RSS = "Mainfeed. aspx? Cate = 7" Visible = "True" Cate = "7" />
</ Navigation >
You can use datatable. Select to query XML data by using the following methods: Dataset myds = New Dataset ();
Myds. readxml ( " Catalog. xml " );
If (Request. querystring [ " Cate " ] ! = Null )
{
Querystr="Cate ="+Request. querystring ["Cate"];
}
Datarow [] row = Myds. Tables [ 0 ]. Select (querystr );
If (Row. Length > 0 )
{
URL=Row [0] ["URL"]. Tostring ();
}
at first, I used the above method to query the correct results, but when the catalog. when the Cate of a node in XML is greater than 10, for example, Cate = 10. tables [0]. select ("Cate = 10") cannot query nodes with Cate = 10. At first, I was puzzled because I think Cate is processed as an int type in myds. Later, I thought about whether dataset treats cate as a string when the Cate turns to a double-digit number? I changed the code to
querystr = "Cate = '" + request. querystring ["Cate"] + "'";
the problem is solved.