我正在使用以下PHP代码从NOAA潮汐报告站API读取XML数据:
$rawxml = file_get_contents(
"http://opendap.co-ops.nos.noaa.gov/axis/webservices/activestations/"
."response.jsp?v=2&format=xml&Submit=Submit"
);
$rawxml = utf8_encode($rawxml);
$ob = simplexml_load_string($rawxml);
var_dump($ob);
不幸的是,我最终得到了以下内容:
object(SimpleXMLElement)#246 (0) { }
在我看来,XML格式完全正确 - 为什么它不能解析?从查看另一个问题(Simplexml_load_string() fail to parse error)中,我得出的想法是头部可能是问题所在——http调用确实返回了"ISO-8859-1"字符集值。但加入 utf8_encode()
的调用似乎行不通。
特别令人困惑的是,simplexml_load_string()
实际上并没有失败——它返回了一串愉快的XML数组,只是里面没有任何内容!
The element type "shef_id" must be terminated by the matching end-tag "</shef_id>"
的错误提示。 - Sergiu Paraschiverror_reporting(E_ALL);
ini_set('display_errors',true);
libxml_use_internal_errors(false);
- IMSoP