PHP:简单XML没有解析xlink:href

时间:2017-06-21 08:00:41

标签: php xml xlink

我有一个XML文件,我从卷曲响应中得到。 当我在浏览器中调用该文件时,它看起来像这样:

<result xsi:schemaLocation="http://mylink.com/xsd/1.0/item.xsd">
<item id="12345">
<name>Product X</name>
<images>
<image lastUpdate="2017-01-18T11:33:05+02:00">
<sizes>
<size maxwidth="74" width="74" height="59" filesize="2452" xlink:href="http://mylink.com/images/1008374"/>
<size maxwidth="320" width="320" height="256" filesize="34502" xlink:href="http://mylink.com/images/1008375"/>
<size maxwidth="800" width="750" height="600" filesize="175894" xlink:href="http://mylink.com/images/1008376"/>
</sizes>
</image>
</images>
</item>
</result>

但是当我用SimpleXmlElement解析它时,它看起来像这样:

SimpleXMLElement Object
(
    [item] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [id] => 12345
                )

            [name] => Product X
        )
        [images] => SimpleXMLElement Object
                (
                    [image] => Array
                        (
                            [0] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [lastUpdate] => 2017-01-18T11:33:05+02:00
                                        )

                                    [sizes] => SimpleXMLElement Object
                                        (
                                            [size] => Array
                                                (
                                                    [0] => SimpleXMLElement Object
                                                        (
                                                            [@attributes] => Array
                                                                (
                                                                    [maxwidth] => 74
                                                                    [width] => 74
                                                                    [height] => 74
                                                                    [filesize] => 3476
                                                                )

                                                        )

                                                    [1] => SimpleXMLElement Object.....

因此我的图像节点中不再有xlink:href属性。我读了一些关于添加属性的内容,但我不知道在哪里,因为在生成SimpleXML-Element时会切断xlink元素。 有谁知道如何获得xlink属性?

0 个答案:

没有答案