Something like this would work. I haven't tested this, so
the XPath
may need to be tweaked.
XPathDocument yourDoc = new
XPathDocument(Server.MapPath("yourDoc.xml"));
XPathNavigator navDoc = yourDoc.CreateNavigator();
XPathNodeIterator roads = navDoc.Select("//city[ name='Cali']//road");
string roadName = "";
if (roads.Count > 0)
{
while (roads.MoveNext())
{
roadName = roads.Current.GetAttribute("name",
"");
}
}
XPathNavigator is very fast and efficient based on what I've
seen.
On 12/11/07, White Rain <snowman908070 yahoo.com> wrote:
> Hello,
>
> My xml looks like:
>
> <root>
>
> <city name="Cali">
> <road name="xxx" />
> <roat name="xxx1" />
> </city>
> <city name="blah">
> <roat name="1234" />
> <road name="2342" />
> </city>
>
> </root>
>
>
> I want to get all the roads for a specific city using
the attribute, for example: give me all the roads in a city
where the city name is "Cali".
>
> What is the fastest way to do this?
>
>
>
____________________________________________________________
________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9
tAcJ
>
>
>
> --- List Settings ---
> http://aspadvice.com/list
s/
>
>
--- List Settings ---
http://aspadvice.com/list
s/
|