473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Yahoo API and XPath problem

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.
Nov 12 '05 #1
2 1688

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" <so*****@somewhere.com> a écrit dans le message de news:
OR**************@TK2MSFTNGP12.phx.gbl...
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.

Nov 12 '05 #2


Someone wrote:

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.


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
http://JavaScript.FAQTs.com/
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Philipp Lenssen | last post by:
I want to try the new Yahoo API, but I get the PHP5 error message Unknown encoding "utf-8" in the marked line below... (After that, applying the Xpath will fail as symptom of the first bug.) ...
0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
1
by: Alastair Cameron | last post by:
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the...
1
by: Phoebian | last post by:
Hi all, Here is a little concept problem, and I need some guideline. I am currently developing a application which delivers XML files. I want then to sequentially perform some actions on...
4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a...
3
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
9
by: StewartS | last post by:
Hi there, I'm looking to display the Yahoo Weather feed on my website (http://developer.yahoo.com/weather/). I am using Visual Web Developer 2005. Everything works fine while parsing normal...
3
by: abcd_68 | last post by:
Hi there, I'm using, for the first time, the JDK1.5 Xpath API. I need to find elements in a Hibernate-generated .hbm.xml file. These files come with a <!DOCTYPE header mentioning a remote URL....
6
by: J.Marsch | last post by:
I must be completely losing my mind. I have some code that writes to config files. It works great with app.config files, but fails miserably with web.config files. For the life of me, I cannot...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.