好吧,XML 是 GETable。至于有效,它缺少<?xml version="1.0"?>
,但我认为它不是必需的。
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="5" yahoo:created="2010-03-09T05:09:03Z" yahoo:lang="en-US" yahoo:updated="2010-03-09T05:09:03Z" yahoo:uri="http://query.yahooapis.com/v1/yql?q=select+*+from+html+where+xpath%3D%22%2F%2Fmeta%22+and+url%3D%22http%3A%2F%2Fwww.cnn.com%22"><results><meta content="HTML Tidy for Java (vers. 26 Sep 2004), see www.w3.org" name="generator"/><meta content="1800;url=?refresh=1" http-equiv="refresh"/><meta content="CNN.com delivers the latest breaking news and information on the latest top stories, weather, business, entertainment, politics, and more. For in-depth coverage, CNN.com provides special reports, video, audio, photo galleries, and interactive guides." name="Description"/><meta content="CNN, CNN news, CNN.com, CNN TV, news, news online, breaking news, U.S. news, world news, weather, business, CNN Money, sports, politics, law, technology, entertainment, education, travel, health, special reports, autos, developing story, news video, CNN Intl" name="Keywords"/><meta content="text/html; charset=iso-8859-1" http-equiv="content-type"/></results></query><!-- total: 250 -->
在我的本地服务器(PHP 5.3)上对其进行了测试,没有报告错误。我已经使用了您的源代码,并且可以正常工作。这是一个 print_r():
SimpleXMLElement Object
(
[results] => SimpleXMLElement Object
(
[meta] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[content] => HTML Tidy for Java (vers. 26 Sep 2004), see www.w3.org
[name] => generator
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[content] => 1800;url=?refresh=1
[http-equiv] => refresh
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[content] => CNN.com delivers the latest breaking news and information on the latest top stories, weather, business, entertainment, politics, and more. For in-depth coverage, CNN.com provides special reports, video, audio, photo galleries, and interactive guides.
[name] => Description
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[content] => CNN, CNN news, CNN.com, CNN TV, news, news online, breaking news, U.S. news, world news, weather, business, CNN Money, sports, politics, law, technology, entertainment, education, travel, health, special reports, autos, developing story, news video, CNN Intl
[name] => Keywords
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[content] => text/html; charset=iso-8859-1
[http-equiv] => content-type
)
)
)
)
)
我建议您对 URL 进行编码,但这已经完成了。您可以尝试使用 cURL 执行查询。