ASP.NET 2.0: how to use XPath?
If we can get a collection of x nodes via XPath in ASP.NET 2.0? Then doing checking per the attrs of开发者_Python百科 them.
<x-list>
<x id="1" enable="On" url="http://abc.123.dev"/>
<x id="2" enable="Off" url="http://asd.com"/>
<x id="3" enable="On" url="http://plm.xcv.tw"/>
</x-list>
Thanks for any help. Ricky
Here's a sample that'll retrieve all of your 'x' nodes that are enabled:
XmlNodeList nodes = root.SelectNodes("/x-list/x[@enable='On']");
foreach (XmlNode node in nodes)
{
...
}
I find w3schools a good place to look for XPath tutorials.
XmlDocument xDocument = new XmlDocument();
xDocument.LoadXml(xmlString);
XmlNodeList xList = xDocument.SelectNodes("x-list/x");
if (xList.Count > 0)
{
foreach (XmlNode x in xList)
{
string id = x.Attributes["id"].Value;
string enable = x.Attributes["enable"].Value;
string url = x.Attributes["url"].Value;
if (enable.Equals("On")
{
...
}
else
{
...
}
}
}
else
{
...
}
精彩评论