According to another question I can select individual XML fields with a YQL query and it works just fine when I test it:
SELECT statistics.subscriberCount FROM xml
WHERE url='http://gdata.youtube.com/feeds/api/users/{$id}'
However when I try to select individual XML fields from Google’s “unofficial” weather XML API I always get empty results (though SELECT * does work).
I know my understanding of both XML and YQL are not complete but what am I missing? (Here’s my query in the YQL console)
(I have managed to query it using XPATH with the itemPath parameter and SELECT *)
My intended query
SELECT current_conditions FROM xml
WHERE url="http://www.google.com/ig/api?weather=Tbilisi"
Results
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"
yahoo:count="0" yahoo:created="2012-02-27T11:56:15Z" yahoo:lang="en-US">
<results/>
</query>
Results of SELECT *
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"
yahoo:count="1" yahoo:created="2012-02-27T11:57:18Z" yahoo:lang="en-US">
<results>
<xml_api_reply version="1">
<weather mobile_row="0" mobile_zipped="1" module_id="0"
row="0" section="0" tab_id="0">
<forecast_information>
<city data="Tbilisi, Tbilisi"/>
<postal_code data="Tbilisi"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2012-02-27"/>
<current_date_time data="1970-01-01 00:00:00 +0000"/>
<unit_system data="US"/>
</forecast_information>
<current_conditions>
<condition data="Overcast"/>
<temp_f data="34"/>
<temp_c data="1"/>
<humidity data="Humidity: 80%"/>
<icon data="/ig/images/weather/cloudy.gif"/>
<wind_condition data="Wind: NE at 6 mph"/>
</current_conditions>
<forecast_conditions>
<day_of_week data="Mon"/>
<low data="28"/>
<high data="37"/>
<icon data="/ig/images/weather/mostly_sunny.gif"/>
<condition data="Mostly Sunny"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Tue"/>
<low data="30"/>
<high data="41"/>
<icon data="/ig/images/weather/mostly_sunny.gif"/>
<condition data="Mostly Sunny"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Wed"/>
<low data="30"/>
<high data="43"/>
<icon data="/ig/images/weather/mostly_sunny.gif"/>
<condition data="Mostly Sunny"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Thu"/>
<low data="27"/>
<high data="43"/>
<icon data="/ig/images/weather/mostly_sunny.gif"/>
<condition data="Partly Sunny"/>
</forecast_conditions>
</weather>
</xml_api_reply>
</results>
</query>
It turns out not to be anything special about the Google weather API but about how the
SELECTparameter interacts with theitemPathparameter in a YQL query.Personally I find the YQL documentation quite difficult to use for those of us with only a rudimentary understanding of some of the technologies on which it relies.
It seems that when you
SELECT ... FROM rssthat there is an implieditemPathwhich points to the repeateditemfield of a feed. But when youSELECT ... FROM xmlyou need to specify anitemPathmanually. If there’s no repeating part of your XML it’s pretty arbitrary what you set it to.Now once you have an
itemPathset you can thenSELECTparticular fields using the dot notation. Note that you can specify subfields which are XML attributes using theSELECTdot notation, but you cannot specify them using the slash notation in theitemPathbut no diagnostics help you find such a beginner error…My new query
Results