Groups | Blog | Home
all groups > dotnet xml > april 2005 >

dotnet xml : Yahoo API and XPath problem


Someone
4/12/2005 7:41:41 PM
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.

Lionel LASKE
4/13/2005 2:19:55 PM

I think that with XmlDocument, the XMLSchema is validated at first load.
Try with a XmlTextReader and disable validation. Something like this:

myXmlTextReader = new XmlTextReader (args(0))
myXmlValidatingReader = new XmlValidatingReader(myXmlTextReader)
myXmlValidatingReader.ValidationType = ValidationType.None

I hope it could helps.

Lionel.

"Someone" <someone@somewhere.com> a écrit dans le message de news:
OReNUJ9PFHA.1176@TK2MSFTNGP12.phx.gbl...
[quoted text, click to view]

Martin Honnen
4/13/2005 2:20:37 PM


[quoted text, click to view]


[quoted text, click to view]

See here on how to use a prefix bound to the default namespace:
<http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button