Does simplexml_load_string have an error?

when I use simplexml_load_string, I find the question, lose data, after use.

$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));

execution result:

  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
        )

)

Where is the data: "An effective algorithm for the one-on-one shortest path" on road maps "?

I hope the xml for array.but data is lost? thank. I want the result:

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
    )

)

)
+3
source share
1 answer

First rule of SimpleXMLElement: you are not print_r()or var_dump()SimpleXMLElement Objects

As for why you do not see this information, see this note in the documentation :

. SimpleXML . var_dump() , .

, :

$xmlObj = simplexml_load_string($xml);
$title = (string) $xmlObj->inproceedings->title;

SimpleXMLElement , , (string) ( strval()). .

, SimpleXML?

IMSoP simplexml_dump() simplexml_tree() . GitHub.

+3

All Articles