【问题标题】:How do I query an XML service using YQL?如何使用 YQL 查询 XML 服务?
【发布时间】:2011-10-19 09:17:52
【问题描述】:

我正在使用YQL Console 来试验查询 REST XML Web 服务。

我找到了一个简单的公共服务。

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.

【问题讨论】:

    标签: xml web-services rest yql


    【解决方案1】:

    根据需要过滤结果的正确键不是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 &lt;tablename&gt; 来查看给定表的键。

    desc xml
    

    (Try this query in the YQL console)

    xml 表的情况下,itemPath 可以是 XPath 表达式或 E4X 虚线路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      相关资源
      最近更新 更多