2011-08-15 33 views
0

我使用YQL控制檯運行下面的查詢:YQL選擇XML

select * 
    from xml 
    where url="http://www.inova.org/patient-and-visitor-information/facilities/inova-fair-oaks-hospital/plan-your-visit/index.jsp" 
     and itemPath="html.body.form" 

沒有返回結果。我也嘗試使用xpathcss只是爲了咧嘴笑,但我沒有得到任何結果。如果我刪除第二個過濾器,我會得到頁面標記。難道我做錯了什麼?這是一個XHTML頁面(根據文檔類型),所以select * from html不起作用。

謝謝。

UPDATE

我已經更新了我的查詢語法的一個查詢,似乎至少返回的結果,但我需要深入瞭解。我真的需要去是這樣的:

select * 
    from xml 
    where url="http://www.inova.org/patient-and-visitor-information/facilities/inova-fair-oaks-hospital/plan-your-visit/index.jsp" 
     and itemPath="html.body.form.div#wrapper.div#page.div#content" 

不幸的是,語法訪問由ID特定的DIV不工作,我還沒有找到實現這一目標的div(一的任何方式與id="content"),根本返回任何結果。

UPDATE

我迷迷糊糊的,我的意思跌跌撞撞到YQL查詢工作(就目前而言,讓我們無視它是多麼脆弱):

select * 
    from xml 
    where url="http://www.inova.org/patient-and-visitor-information/facilities/inova-fair-oaks-hospital/plan-your-visit/index.jsp" 
     and itemPath="html.body.form.div.1.div.4.div.2" 

任何建議讓它變得更脆弱(並且最好是防彈的)會真的,非常感激。

回答

0

我認爲這可能與他們的方式xhtml寫入,而不是實際的YQL語句。

火狐拋出試圖訪問YQL語句直接當這個錯誤:如果您在使用jQuery你可以得到它周圍有東西沿着這些路線

XML Parsing Error: undefined entity 
Location:http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%27http%3A%2F%2Fwww.inova.org%2Fpatient-and-visitor-information%2Ffacilities%2Finova-fair-oaks-hospital%2Fplan-your-visit%2Findex.jsp%27 
Line Number 307, Column 12: 

Fairfax, VA&nbsp; 22033<br/> 
-----------^ 

$.ajax({ 
    type : 'GET', 
    dataType : 'xml', 
    url : 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22http%3A%2F%2Fwww.inova.org%2Fpatient-and-visitor-information%2Ffacilities%2Finova-fair-oaks-hospital%2Fplan-your-visit%2Findex.jsp%22', 
    success : function(xhtml) { 
     //find all nodes 
     $(xhtml).find('h1').each(function(){ 
      console.log($(this).html()) 
     }); 

     //target specific node 
     console.log($('#content').html()) 
    } 
}) 
+0

你說得對。我經歷了很多很多的語法迭代,並且粘貼了一個並不完全正確的語法迭代。我已經糾正它到一個工作(閱讀:返回結果),但我需要深入幾層。我相應地更新了我的問題。 –

+0

哦,nm。我剛剛重讀了你的答案,這一次實際上點擊了。我會看看頁面,但我認爲YQL會清理那些東西,這可能解釋爲什麼上面修改的查詢至少在某種程度上起作用。 –

+0

這基本上是遍歷JSON響應的方式。你仍然需要外部編碼來獲得所有的h1節點。即使採用新方法,瀏覽器仍然會輸出xml解析錯誤。 – RVCA18