是否可以使用YQL从XML或RSS中仅选择属性的值?
我有一些来自XML和RSS的YQL查询,返回的内容比我想要选择的要多。我将从itemPath获取所有XML,直到属性值,然后我必须对属性值进行筛选,以挖掘出我想要的值: 此查询:是否可以使用YQL从XML或RSS中仅选择属性的值?,xml,rss,yql,xml-attribute,google-weather-api,Xml,Rss,Yql,Xml Attribute,Google Weather Api,我有一些来自XML和RSS的YQL查询,返回的内容比我想要选择的要多。我将从itemPath获取所有XML,直到属性值,然后我必须对属性值进行筛选,以挖掘出我想要的值: 此查询: SELECT current_conditions.temp_c.data FROM xml WHERE url="http://www.google.com/ig/api?weather=Tbilisi" AND itemPath="//weather" SELECT condition.temp
SELECT current_conditions.temp_c.data FROM xml
WHERE url="http://www.google.com/ig/api?weather=Tbilisi"
AND itemPath="//weather"
SELECT condition.temp FROM rss
WHERE url="http://weather.yahooapis.com/forecastrss?w=1965878&u=c"
返回所有这些:
<results>
<weather>
<current_conditions>
<temp_c data="-7"/>
</current_conditions>
</weather>
</results>
<results>
<item>
<yweather:condition
xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" temp="1"/>
</item>
</results>
返回所有这些:
<results>
<weather>
<current_conditions>
<temp_c data="-7"/>
</current_conditions>
</weather>
</results>
<results>
<item>
<yweather:condition
xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" temp="1"/>
</item>
</results>
而我想要的只是:
<results>1</results>
在使用YQL选择XML属性时,是否有任何方法可以获得更简洁的结果,这样我就不必在代码中进一步解析结果
一个用例是当我想使用yql.query.multi在一个查询中查询多个源时。当所有这些周围的XML都返回给我时,我没有得到一个好的整洁的行。这给了你什么
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"
这给了你什么
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"
您需要使用HTML5解析器。使用@Murry McDonald的答案并稍加修改应该对你有用
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"
您需要使用HTML5解析器。使用@Murry McDonald的答案并稍加修改应该对你有用
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"
这给了我空的结果:向select语句中添加并压缩=html5这给了我空的结果:向select语句中添加并压缩=html5真的吗?这是一个老生常谈的问题,看起来API已经不存在了。我刚从URL得到一个404,所以查询失败。对你有用吗?@hippietrail是的,你是对的。我刚刚看到它返回404。但是我试着用YQL回答你的问题选择属性的值,这是你应该能够用上面的答案来做的事情。真的吗?这是一个老生常谈的问题,看起来API已经不存在了。我刚从URL得到一个404,所以查询失败。对你有用吗?@hippietrail是的,你是对的。我刚刚看到它返回404。但我试图用YQL回答您的问题选择属性的值,这是您应该能够用上面的答案来做的事情。