【发布时间】:2014-02-09 14:49:26
【问题描述】:
当我使用 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
)
)
数据“:路线图上一对一最短路径问题的有效算法”在哪里?
我希望 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 对象
title中。另见stackoverflow.com/questions/5132231/… -
不要
print_rSIMPLEXML 类,或者至少不要根据其输出得出任何结论。它们为您提供了某种表示形式,可以帮助您稍微识别事物,但在很多情况下它在表面之下是模糊的。 -
用“有错误?”来表达问题。大多数情况下,这不是 Stackoverflow 的有效问题,而是 PHP bugtracker 中的搜索请求(此规则有例外,但此问题不属于其中)。另见github.com/IMSoP/simplexml_debug