php 预期 XML 解析器错误开始标记
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12059873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XML Parser Error Start Tag Expected
提问by virusbogdan
function retrieveProfile()
{
$url = "http://steamcommunity.com/profiles/{$this->steamID64}/?xml=1";
$profileData = simplexml_load_string($url);
if(!empty($profileData->error)) { return NULL; }
$this->friendlyName = (string) $profileData->steamID;
}
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found
Warning: simplexml_load_string() [function.simplexml-load-string]: http://steamcommunity.com/profiles/76561197991676121/?xml=1
Warning: simplexml_load_string() [function.simplexml-load-string]: ^
警告:simplexml_load_string() [function.simplexml-load-string]:实体:第 1 行:解析器错误:预期开始标记,未找到“<”
警告:simplexml_load_string() [function.simplexml-load-string]:http://steamcommunity.com/profiles/76561197991676121/?xml =1
警告:simplexml_load_string() [function.simplexml-load-string]:^
This is the XML file:
这是 XML 文件:
http://steamcommunity.com/profiles/76561197991676121/?xml=1
http://steamcommunity.com/profiles/76561197991676121/?xml=1
I got no ideea why it does not work and yes it have <?xml version="1.0" encoding="UTF-8" standalone="yes"?>header !
Tried $profileData = new SimpleXMLElement(file_get_contents($url))too but I get the same result.
我不知道为什么它不起作用,是的,它有<?xml version="1.0" encoding="UTF-8" standalone="yes"?>标题!也尝试$profileData = new SimpleXMLElement(file_get_contents($url))过,但我得到了相同的结果。
Why is this happening ? How can I solve it? I am searching for 3 hours and see only answers that won't help me .
Errors : http://img824.imageshack.us/img824/9464/errorszz.png
为什么会这样?我该如何解决?我搜索了 3 个小时,只看到对我没有帮助的答案。
错误:http: //img824.imageshack.us/img824/9464/errorszz.png
EDIT1 : simplexml_load_string was one of my mistakes but now I get even more errors with simplexml_load_file - Tells me that the document is empty... (Not true !)
EDIT1:simplexml_load_string 是我的错误之一,但现在 simplexml_load_file 出现更多错误 - 告诉我该文档为空...(不是真的!)
回答by Tchoupi
You are loading the URL as your XML source. You should have:
您正在加载 URL 作为您的 XML 源。你应该有:
$profileData = simplexml_load_file($url);
回答by virusbogdan
Url was changing from steamcommunity.com/profiles/76561197991676121/?xml=1 to http://steamcommunity.com/id/virusbogdan/?xml=1. Obviously the first link returns null so there was an error. Problem solved !
网址从 steamcommunity.com/profiles/76561197991676121/?xml=1 更改为http://steamcommunity.com/id/virusbogdan/?xml=1。显然第一个链接返回 null 所以有一个错误。问题解决了 !

