2011-10-19 34 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点缀路径。