Using C#, ASP.NET
I'm trying to implement Yahoo search API. I can sent the HTTP request and
get back the results. The problem I have is that I don't know how to use
XPath with the results than comes back. I coded XPath before successfully,
but Yahoo XML is a bit more complex.
Here is part of Yahoo XML result:
<?xml version="1.0" encoding="UTF-8" ?>
<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:yahoo:srch" xsi:schemaLocation="urn:yahoo:srch
http://api.search.yahoo.com/WebSearchService/V1/WebSearchResponse.xsd"
totalResultsAvailable="12841248" totalResultsReturned="10"
firstResultPosition="1">
<Result>
<Title>some text</Title>
...
</Result>
</ResultSet>
I load the XML string into an XmlDocument xmlDoc.
Code like this does not work:
XmlNodeList nodes = xmlDoc.SelectNodes("/ResultSet/Result");
I tried using XmlNamespaceManager, but can't really understand how to use
that. Of course it did not work.
If I modify Yahoo XML and load it from my hard disk as follows:
<?xml version="1.0" encoding="UTF-8" ?>
<ResultSet totalResultsAvailable="12841248" totalResultsReturned="10"
firstResultPosition="1">
<Result>
<Title>some text</Title>
...
</Result>
</ResultSet>
This I can get to work. Which makes me believe the namespace or something
like that is breaking my XPath.
Any help will be much appreciated.
Thanks.