2012-03-03 32 views
1

我有一些YQL來自XML和RSS的查詢返回的比我想要的要多SELECT。我得到一切從itemPath的XML下來的屬性值,然後我不得不進行篩選,以挖出只是我想要的值:是否可以使用YQL從XML或RSS中僅選擇屬性的值?

這個查詢:

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

回報這一切:

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

,但我需要的是:

<results>-7</results> 

與此查詢:

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

回報這一切:

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

,而我要的就是這樣的:

<results>1</results> 

有沒有什麼辦法讓這樣的更簡潔結果時選擇XML屬性YQL,所以我不必在我的代碼中進一步解析結果?

一個用例是當我想要使用yql.query.multi在一個查詢中查詢多個源時。當所有這些周圍的XML都返回給我時,我不會回到一個漂亮的「行」。

回答

1

這會給你什麼?

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" 
+0

這讓我空的結果:''附加 – hippietrail 2012-03-04 01:55:23

+0

'和緊湊= html5'到你的SELECT語句 – 2015-02-09 12:45:15

0

您需要使用HTML5解析器。使用@Murry麥當勞的答案和修改它應該爲你工作。

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" 
+0

真的嗎?這是一個古老的問題,現在API看起來已經消失了。我只是從URL中獲取404,所以查詢失敗。對你起作用嗎? – hippietrail 2015-02-09 13:42:11

+1

@hippietrail是的,你是對的。我剛剛看到它返回了404。但我試圖回答你的問題「使用YQL選擇屬性的值」,這是你應該能夠使用上述答案做的事情。 – 2015-02-09 13:47:38

相關問題