简体   繁体   English

PHP SimpleXMLElement从URL解析xml

[英]PHP SimpleXMLElement parsing xml from url

I'm trying to parse a XML file from a URL using SimpleXMLElement. 我正在尝试使用SimpleXMLElement从URL解析XML文件。 When i try: 当我尝试:

$url = 'http://dl.dropbox.com/u/27440550/test.xml';
$xml = new SimpleXMLElement($url, 0, true, "", false);

Everything works fine, i can access the XML document and parse it. 一切正常,我可以访问XML文档并进行解析。 Notice the url is a link to my dropbox public folder where i stored the xml file. 请注意,URL是我存储xml文件的保管箱公用文件夹的链接。

When i try to get the file directly from the url: 当我尝试直接从url获取文件时:

$url = 'https://multidoc.eia-fr.ch/record/1220/export/xd';
$xml = new SimpleXMLElement($url, 0, true, "", false);

I get weird errors: 我收到奇怪的错误:

Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: Entity: line 1: parser error : Start tag expected, '&lt;' not found in C:\wamp\www\metamin\getxml.php on line 5

Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: https://multidoc.eia-fr.ch/record/1220/export/xd in C:\wamp\www\metamin\getxml.php on line 5

Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: ^ in C:\wamp\www\metamin\getxml.php on line 5

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\wamp\www\metamin\getxml.php on line 5

Exception: String could not be parsed as XML in C:\wamp\www\metamin\getxml.php on line 5

So I think it's not recognizing it as a XML file but why? 因此,我认为它不能将其识别为XML文件,但是为什么呢? Am I not doing the same thing? 我不是在做同一件事吗?

Could be because of the SSL encryption - note the https in the URL, although I am not sure. 可能是因为SSL加密 - 请注意在URL https的,虽然我不知道。

Thanks to Jeff 感谢杰夫

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM