1

I've got some YQL queries from XML and RSS that are returning more than what I want to SELECT. I'm getting all the XML from the itemPath down to the attribute value, which I then have to sift through to dig out just the values I want:

This query:

SELECT current_conditions.temp_c.data FROM xml
    WHERE url="http://www.google.com/ig/api?weather=Tbilisi"
    AND itemPath="//weather"

returns all this:

    <results>
        <weather>
            <current_conditions>
                <temp_c data="-7"/>
            </current_conditions>
        </weather>
    </results>

but all I need is:

    <results>-7</results>

and this query:

SELECT condition.temp FROM rss
    WHERE url="http://weather.yahooapis.com/forecastrss?w=1965878&u=c"

returns all this:

    <results>
        <item>
            <yweather:condition
                xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" temp="1"/>
        </item>
    </results>

whereas what I want is just this:

    <results>1</results>

Is there any way to get more concise results like these when selecting XML attributes with YQL so I don't have to parse the result further in my code?

One use case is when I want to query several sources within one query using yql.query.multi. I don't get back a nice neat "row" when all this surrounding XML is returned to me.

hippietrail
  • 15,848
  • 18
  • 99
  • 158

2 Answers2

1

What does this give you?

SELECT current_conditions.temp_c.data FROM xml
  WHERE url="http://www.google.com/ig/api?weather=Tbilisi"
  AND itemPath="//weather/current_conditions/temp_c/@data"
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Murray McDonald
  • 631
  • 4
  • 5
0

You need to use the HTML5 parser. Using @Murry McDonald's answer and modifying it a little should work for you.

SELECT current_conditions.temp_c.data FROM xml
  WHERE url="http://www.google.com/ig/api?weather=Tbilisi"
  AND itemPath="//weather/current_conditions/temp_c/@data" AND compact="html"
Lucky Soni
  • 6,811
  • 3
  • 38
  • 57
  • Really? This is an old question and it looks like the API is gone now. I just get a 404 from the URL so the query fails. Does it work for you? – hippietrail Feb 09 '15 at 13:42
  • 1
    @hippietrail Yes, you are right. I just saw that it returns a 404. But I was trying to answer your question "select attribute's value using YQL" and this is something that you should be able to do using the above answer. – Lucky Soni Feb 09 '15 at 13:47