简单的 XML 命名空间警告


Simple XML namespace warning

我正在尝试使用simplexml解析以下XML...

http://datapoint.metoffice.gov.uk/public/data/txt/wxfcs/regionalforecast/xml/500?key=ed47ad61-5033-48c8-bf7c-6c4c0b17c3f3

但是一旦我添加行...

$xml = simplexml_load_file('http://datapoint.metoffice.gov.uk/public/data/txt/wxfcs/regionalforecast/xml/500?key=ed47ad61-5033-48c8-bf7c-6c4c0b17c3f3');

我得到和错误喜欢

namespace warning : xmlns: URI www.metoffice.gov.uk/xml/metoRegionalFcst is not absolute

我似乎无法弄清楚如何解决这个问题。

只需在simplexml_load_file之前添加@

喜欢

$xml = @simplexml_load_file('http://datapoint.metoffice.gov.uk/public/data/txt/wxfcs/regionalforecast/xml/500?key=ed47ad61-5033-48c8-bf7c-6c4c0b17c3f3'(;

libxml_use_internal_errors(true);
$xml = simplexml_load_file($file->getTempName());

us3.php.net/manual/es/function.simplexml-load-file.php
us3.php.net/manual/es/function.libxml-use-internal-errors.php
us3.php.net/manual/es/simplexml.examples-errors.php

基本上,由于这只是来自PHP的警告,您可以通过执行任何适合您的方法来抑制它。

它可能是其中之一

1. @simplexml_load_string($response) :' PHP 支持一个错误控制运算符:at 符号 (@( 表示更多 https://www.php.net/manual/en/language.operators.errorcontrol.php。

2. simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOWARNING);https://github.com/AuthorizeNet/sdk-php/issues/135

如果它有帮助,你可以做下一件事

// Set the url of your XML file
 $XmlPath = resource_path('xml/').'mifile.xml';
//Parse the XML file, dont forget use the "Nowarning lib" and "Compact" those are so usefull
 $Codes = simplexml_load_file ( $XmlPath , 'SimpleXMLElement' , LIBXML_NOWARNING | LIBXML_COMPACT   , null , false );