simplexml没有返回子项

时间:2011-07-26 14:12:27

标签: php xml parsing simplexml

我正在尝试解析以下XML但我无法从SimpleXML中检索任何子代 该 WhateverItem是第一个元素,它包含几个子元素,如whateverItem:Properties,whateverItem:Test等。 应该

$xmlDoc = new SimpleXMLElement($xml);
var_dump($xmlDoc->children());

还给孩子们?

<whateverItem:item
 xmlns:prop="http://whatever.de/core/01/properties/" 
 xmlns:srel="http://whatever.de/core/01/structural-relations/" 
 xmlns:xlink="http://www.w3.org/1999/xlink"   
 xml:base="http://mybasewhatever:8080"  
 xlink:type="simple" 
 xlink:title="My Item Title" 
 xlink:href="/ir/item/whatever:1220" 
 last-modification-date="2011-07-07T12:52:55.415Z" >

     <whateverItem:properties     
     xlink:type="simple" 
     xlink:title="Properties" 
     xlink:href="/ir/item/whatever:1220/properties">


    <prop:creation-date>2011-07-04T15:17:50.855Z</prop:creation-date>
    <srel:created-by  xlink:type="simple" xlink:title="System Administrator User" xlink:href="/aa/user-account/whatever:exuser1" />
    <prop:public-status>released</prop:public-status>


    <prop:version  xlink:type="simple" xlink:title="This Version" xlink:href="/ir/item/whatever:1220:4">
        <version:number >4</version:number>
        <version:date >2011-07-07T12:52:55.415Z</version:date>
        <version:status >released</version:status> 
         <srel:modified-by  xlink:type="simple" xlink:title="System Administrator User" xlink:href="/aa/user-account/whatever:exuser1" />
         <version:comment >Status changed to released for Item whatever:1220.</version:comment>
    </prop:version>

    <prop:latest-version  xlink:type="simple" xlink:title="Latest Version" xlink:href="/ir/item/whatever:1220:4">
        <version:number >4</version:number>
        <version:date >2011-07-07T12:52:55.415Z</version:date>
    </prop:latest-version>

    <prop:latest-release  xlink:type="simple" xlink:title="Latest public version" xlink:href="/ir/item/whatever:1220:4">
        <release:number >4</release:number>
        <release:date >2011-07-07T12:52:55.415Z</release:date>
    </prop:latest-release>
</whateverItem:properties>
...
<whateverItem:Test></whateverItem:Test>
</whateverItem:item>

1 个答案:

答案 0 :(得分:1)

您是否在实际的XML输入中声明了'whateverItem'命名空间?尝试通过xmllint(大多数Linux发行版中的命令行实用程序)运行输入,看看它是否会解决任何问题,首先。