2011-10-19 32 views
1

我正在使用YQL Console來試驗查詢REST XML Web服務。如何使用YQL查詢XML服務?

我找到了一個簡單的公共服務來玩。

http://www.thomas-bayer.com/sqlrest/CUSTOMER/-151612345/

回報

<CUSTOMER xmlns:xlink="http://www.w3.org/1999/xlink"> 
    <ID>-151612345</ID> 
    <FIRSTNAME>Deepthi</FIRSTNAME> 
    <LASTNAME>Deep</LASTNAME> 
    <STREET>440 - 20th Ave.</STREET> 
    <CITY>Los Angeles</CITY> 
</CUSTOMER> 

如果我使用查詢:

select * 
from xml 
where url='http://www.thomas-bayer.com/sqlrest/CUSTOMER/-151612345/' 

我得到這個XML返回。但是,如果我嘗試將數據限制爲單個元素,例如:

select * 
from xml 
where url='http://www.thomas-bayer.com/sqlrest/CUSTOMER/-151612345/' 
    and xpath='//LASTNAME' 

未返回任何結果。

我在做什麼錯?

Click here to display the YQL console with the query loaded.

回答

0

的,只要你想過濾的結果正確的關鍵不是xpath,取而代之的則是itemPath

SELECT * 
FROM xml 
WHERE url='http://www.thomas-bayer.com/sqlrest/CUSTOMER/-151612345/' 
    AND itemPath='//LASTNAME' 

Try this query in the YQL console

您可以通過發出查詢desc <tablename>看到一個給定表中的鍵。

desc xml 

Try this query in the YQL console

xml表的情況下,itemPath可以是XPath表達式或E4X點綴路徑。