- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
当我使用 simplexml_load_string 时,我发现一个问题,使用后丢失数据。
$xml = '<dblp>
<inproceedings key="conf/aaim/He07" mdate="2007-06-28">
<author>Dan He</author>
<title>
<i>BMA</i>
<sup>*</sup>
: An Efficient Algorithm for the One-to-Some Shortest Path Problem on Road Maps.
</title>
<pages>346-357</pages>
<year>2007</year>
<crossref>conf/aaim/2007</crossref>
<booktitle>AAIM</booktitle>
<ee>http://dx.doi.org/10.1007/978-3-540-72870-2_33</ee>
<url>db/conf/aaim/aaim2007.html#He07</url>
</inproceedings>
</dblp>';
print_r(simplexml_load_string($xml));
运行结果:
SimpleXMLElement Object
(
[inproceedings] => SimpleXMLElement Object
(
[@attributes] => Array
(
[key] => conf/aaim/He07
[mdate] => 2007-06-28
)
[author] => Dan He
[title] => SimpleXMLElement Object
(
[i] => BMA
[sup] => *
)
[pages] => 346-357
[year] => 2007
[crossref] => conf/aaim/2007
[booktitle] => AAIM
[ee] => http://dx.doi.org/10.1007/978-3-540-72870-2_33
[url] => db/conf/aaim/aaim2007.html#He07
)
)
数据在哪里“:道路 map 上一对多最短路径问题的有效算法。”?
我希望 xml 到 array.but 数据丢失?谢谢。我想要结果:
Array
(
[0] => Array
(
[inproceedings] =>Array
(
[author] => Dan He
[title] => Array
(
[0] => BMA
[2] => *
[5] => : An Efficient Algorithm for the One-to-Some Shortest Path Problem on Road Maps.
)
[pages] => 346-357
[year] => 2007
[crossref] => conf/aaim/2007
[booktitle] => AAIM
[ee] => http://dx.doi.org/10.1007/978-3-540-72870-2_33
[url] => db/conf/aaim/aaim2007.html#He07
)
)
)
最佳答案
SimpleXMLElement 的第一条规则是:您不要 print_r()
或 var_dump()
SimpleXMLElement 对象
至于为什么看不到信息,看这篇来自documentation的说明:
Note: SimpleXML has made a rule of adding iterative properties to most methods. They cannot be viewed using var_dump() or anything else which can examine objects.
要访问标题,您可以执行以下操作:
$xmlObj = simplexml_load_string($xml);
$title = (string) $xmlObj->inproceedings->title;
SimpleXMLElement 对象的属性本身就是对象,因此您需要通过在开头添加 (string)
(或使用 strval()
)将它们转换为字符串。现在它们的值将被转换为字符串而不是对象。
当您想要检查 SimpleXML 对象时应该使用什么?
您可以使用 IMSoP的 simplexml_dump()
和 simplexml_tree()
辅助函数。这是 project on GitHub .
关于php - simplexml_load_string 有错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21660547/
有谁知道我是否可以强制 SimpleXMLElement 变量始终为数组? 1 name 1 2 nam
我目前正在尝试从谷歌联系人 api 中提取信息。使用库中提供的示例代码: $response = json_encode(simplexml_load_string($val->getResponse
我正在使用此代码读取 xml。 $xml = simplexml_load_string($data); 它读取正确,并且可以通过 $xml->title 等访问数据。 但我需要访问 CDATA 和
我正在尝试加载解析 Google Weather API 响应(中文响应)。 Here是 API 调用。 // This code fails with the following error $xm
调用未定义函数simplexml_load_string() 我在我们服务器上的所有站点上都遇到了这个错误。直到今天一切都正常工作,突然间出现了这个错误。 我检查了 Simplexml,它已经安装在服
我正在处理一个 xml 文件,我试图将其解析为 json 格式,然后解码为一个数组。我主要使用内置的 simplexml_load_string 和 json_encode 来完成此操作。问题是在调用
当我使用 simplexml_load_string 时,我发现一个问题,使用后丢失数据。 $xml = ' Dan He BMA * : An Efficient Algorithm for t
我正在使用 cron 文件实现 facebook 计数功能。其中 cron 每 10 分钟运行一次,并计算一个页面的总点赞数。 for($i=0;$ilink_stat->like_count;
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界. 这篇CFSDN的博客文章PHP simplexml_load_string()函数实例讲解由作者
我的 PHP 代码如下所示,显示空白 我想显示所有带有超链接的记录,例如 $Name 其中 $Id, $Name 来自 XML 提要 $path = 'www.abc.com/test.xml';
未插入值,也未显示错误。知道我的插入发生了什么吗? AD Andorra AE United Arab Emirates 784 AF Afghanistan 784 XML; $x
我阅读了以下 xml 文件: BO1 BO2 使用以下代码时: $xmlResponse = file_get_conte
我想将一个 xml 文件放入我的程序并将其放入一个数组中,这样我就可以将它放入一个表中。 我想知道如何做到这一点,我已经阅读了 php 手册,但我似乎无法掌握它。 做我想做的事,我需要使用simple
常量 XML_PARSE_HUGE 可以作为第三个参数传递给 simplexml_load_string() .根据php.net这个标志: relaxes any hardcoded limit f
我试图在 Python 中找到一个 xml 解释函数(如 simplexml_load_string),但没有成功:/ 假设我有一个字符串中的 xml my_xml_string = """
我正在处理一个我无法编辑的第三方 PHP 库,它已经运行了将近一年。它对来自远程服务器的响应使用 simplexml_load_string。最近,它因大量响应而窒息。这是房地产列表的数据提要,格式如
我见过很多程序员实现 SimpleXML_load_string() 而不是 SimpleXMLElement() 类。使用前者比使用后者有什么好处吗?我读过 PHP manual on simple
我正在使用以下 PHP 代码从 NOAA 的潮汐报告站 API 读取 XML 数据: $rawxml = file_get_contents( "http://opendap.co-ops.n
这个问题在这里已经有了答案: 关闭 9 年前。 Possible Duplicate: Accessing @attribute from SimpleXML 我正在使用一些第三方 API,它们通过
所以我有一个 PHP 脚本,它解析来自 Google Analytics 的 XML 响应。它已经工作了几个星期,但今天我收到了这个警告,简单的 xml 加载字符串没有将 xml 响应转换为 simp
我是一名优秀的程序员,十分优秀!