CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2007
    Posts
    43

    XPath question : something wrong with the my query?

    Code:
    <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,

  2. #2
    Join Date
    Jul 2007
    Posts
    43

    Re: XPath question : something wrong with the my query?

    anybody?

  3. #3
    Join Date
    Mar 2007
    Posts
    90

    Re: XPath question : something wrong with the my query?

    Try using:
    Code:
    XPathNavigator nav = doc.CreateNavigator();
    XPathNodeIterator it = nav.Select("/DIV/UL/LI/UL[@class='sst_clicks']");
    while (it.MoveNext())
    {
    }

  4. #4
    Join Date
    Jul 2007
    Posts
    43

    Re: XPath question : something wrong with the my query?

    nope that didnt work

  5. #5
    Join Date
    Mar 2007
    Posts
    90

    Re: XPath question : something wrong with the my query?

    Note that I had to replace the ampersands with %26.
    Code:
    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);
                }
            }
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured