如何使用 YQL 查询 XML 服务?
我正在使用 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'
不会返回任何结果。
我做错了什么?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据需要过滤结果的正确键不是
xpath
,而是itemPath
。(在 YQL 控制台中尝试此查询)
您可以看到通过发出查询
desc
给定表。YQL 控制台中尝试此查询)
(在 >xml 表中,
itemPath
可以是 XPath 表达式,也可以是 E4X 点路径。The correct key for filtering the results as you want is not
xpath
, instead it isitemPath
.(Try this query in the YQL console)
You can see the keys for a given table by issuing the query
desc <tablename>
.(Try this query in the YQL console)
In the case of the
xml
table, theitemPath
can either be an XPath expression or an E4X dotted path.