如何使用 YQL 查询 XML 服务?

发布于 2024-12-10 11:21:15 字数 1203 浏览 5 评论 0原文

我正在使用 YQL 控制台 来尝试查询 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'

不会返回任何结果。

我做错了什么?

单击此处显示已加载查询的 YQL 控制台。

I'm using the YQL Console to experiment with querying a REST XML web-service.

I found a simple public service to play with.

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

returns

<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>

If I use the query:

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

I get this XML returned. However, if I try to restrict to data to a single element, e.g.:

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

no results are returned.

What am I doing wrong?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚我心虐我身 2024-12-17 11:21:15

根据需要过滤结果的正确键不是 xpath,而是 itemPath

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

(在 YQL 控制台中尝试此查询)

您可以看到通过发出查询 desc 给定表。

desc xml

YQL 控制台中尝试此查询)

(在 >xml 表中,itemPath 可以是 XPath 表达式,也可以是 E4X 点路径。

The correct key for filtering the results as you want is not xpath, instead it is itemPath.

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

(Try this query in the YQL console)

You can see the keys for a given table by issuing the query desc <tablename>.

desc xml

(Try this query in the YQL console)

In the case of the xml table, the itemPath can either be an XPath expression or an E4X dotted path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文