Click to See Complete Forum and Search --> : XPath question : something wrong with the my query?


doglin82
June 4th, 2009, 01:58 AM
<DIV id="sst">
<UL class="sst_queries">
<LI>
<DIV id="124011420">
<DIV class="sst_time">12:40PM</DIV>
<DIV class="sst_query">
<A onmousedown="return si_T('&ID=SERP,158')" href="http://www.bing.com/search?q=dog&FORM=O1HV">dog</A>
<A class="sst_del" onmousedown="return si_T('&ID=SERP,161')" href="http://www.bing.com/history.aspx?dl=0&d=20090603&dlt=128885316114200000&ig=ac152ac9227649ac8ee7d525d6aa6e6a&FORM=ZZHV">x
</A>
</DIV>
</DIV>

<UL class="sst_clicks">
<LI>
<A onmousedown="return si_T('&ID=SERP,148')" href="http://www.dog.com/"><STRONG>Dog</STRONG> Supplies, <STRONG>Dog</STRONG> Beds, Toys &amp; Treats - <STRONG>Dog</STRONG>.com
</A>
<A class="sst_del" onmousedown="return si_T('&ID=SERP,151')" href="http://www.bing.com/history.aspx?dl=0&d=20090603&dlt=128885319380930000&ig=ac152ac9227649ac8ee7d525d6aa6e6a&uh=199f8d38895a9fed11a7&FORM=ZZHV2">x</A>
<DIV class="sst_clickurl">
<A onmousedown="return si_T('&ID=SERP,148')" href="http://www.dog.com/">www.dog.com/</A>
</DIV>
</LI>
<LI>
<A onmousedown="return si_T('&ID=SERP,153')" href="http://en.wikipedia.org/wiki/Dog"><STRONG>Dog</STRONG> - Wikipedia, the free encyclopedia</A>
<A class="sst_del" onmousedown="return si_T('&ID=SERP,156')" href="http://www.bing.com/history.aspx?dl=0&d=20090603&dlt=128885319351500000&ig=ac152ac9227649ac8ee7d525d6aa6e6a&uh=ecfe497f524c4a1845f2&FORM=ZZHV3">x
</A>
<DIV class="sst_clickurl">
<A onmousedown="return si_T('&ID=SERP,153')" href="http://en.wikipedia.org/wiki/Dog">en.wikipedia.org/wiki/Dog</A>
</DIV>
</LI>
</UL>
</LI>
</UL>
</DIV>


XPathNavigator nav = doc.CreateNavigator();

the query i used is
/DIV/UL/LI/UL[@class='sst_clicks']
XPathNodeIterator it = nav.SelectChildren("/DIV/UL/LI/UL[@class='sst_clicks']", "");


However, it is not selecting the nodes. Please let me know what I did wrong.

Thanks,

doglin82
June 4th, 2009, 05:41 PM
anybody?

someuser77
June 5th, 2009, 05:02 PM
Try using:
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator it = nav.Select("/DIV/UL/LI/UL[@class='sst_clicks']");
while (it.MoveNext())
{
}

doglin82
June 5th, 2009, 08:50 PM
nope that didnt work

someuser77
June 6th, 2009, 12:35 AM
Note that I had to replace the ampersands with %26.

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.XPath;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string text = "<DIV id=\"sst\"> <UL class=\"sst_queries\"> <LI> <DIV id=\"124011420\"> <DIV class=\"sst_time\">12:40PM</DIV> <DIV class=\"sst_query\"> <A onmousedown=\"return si_T('%26ID=SERP,158')\" href=\"http://www.bing.com/search?q=dog%26FORM=O1HV\">dog</A> <A class=\"sst_del\" onmousedown=\"return si_T('%26ID=SERP,161')\" href=\"http://www.bing.com/history.aspx?dl=0%26d=20090603%26dlt=128885316114200000%26ig=ac152ac9227649ac8ee7d525d6aa6e6a%26FORM=ZZHV\">x </A> </DIV> </DIV> <UL class=\"sst_clicks\"> <LI> <A onmousedown=\"return si_T('%26ID=SERP,148')\" href=\"http://www.dog.com/\"><STRONG>Dog</STRONG> Supplies, <STRONG>Dog</STRONG> Beds, Toys %26amp; Treats - <STRONG>Dog</STRONG>.com </A> <A class=\"sst_del\" onmousedown=\"return si_T('%26ID=SERP,151')\" href=\"http://www.bing.com/history.aspx?dl=0%26d=20090603%26dlt=128885319380930000%26ig=ac152ac9227649ac8ee7d525d6aa6e6a%26uh=199f8d38895a9fed11a7%26FORM=ZZHV2\">x</A> <DIV class=\"sst_clickurl\"> <A onmousedown=\"return si_T('%26ID=SERP,148')\" href=\"http://www.dog.com/\">www.dog.com/</A> </DIV> </LI> <LI> <A onmousedown=\"return si_T('%26ID=SERP,153')\" href=\"http://en.wikipedia.org/wiki/Dog\"><STRONG>Dog</STRONG> - Wikipedia, the free encyclopedia</A> <A class=\"sst_del\" onmousedown=\"return si_T('%26ID=SERP,156')\" href=\"http://www.bing.com/history.aspx?dl=0%26d=20090603%26dlt=128885319351500000%26ig=ac152ac9227649ac8ee7d525d6aa6e6a%26uh=ecfe497f524c4a1845f2%26FORM=ZZHV3\">x </A> <DIV class=\"sst_clickurl\"> <A onmousedown=\"return si_T('%26ID=SERP,153')\" href=\"http://en.wikipedia.org/wiki/Dog\">en.wikipedia.org/wiki/Dog</A> </DIV> </LI> </UL> </LI> </UL></DIV> ";
XPathDocument doc = new XPathDocument(new MemoryStream(Encoding.ASCII.GetBytes(text)));
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator it = nav.Select("/DIV/UL/LI/UL[@class='sst_clicks']");
while (it.MoveNext())
{
Console.WriteLine(it.Current.InnerXml);
}
}
}
}