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.

2 Answers 2

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"
2
  • This gives me empty results: <results/> Mar 4, 2012 at 1:55
  • add AND compact=html5 to your select statement
    – Lucky Soni
    Feb 9, 2015 at 12:45
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"
2
  • 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? Feb 9, 2015 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 9, 2015 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.