simplexml 不返回子项

发布于 2024-11-26 02:46:32 字数 2357 浏览 1 评论 0原文

我正在尝试解析以下 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>

I am trying to parse the following XML but I cannot retrieve any children from the SimpleXML
The
WhateverItem is the first element and it contains a couple of children like whateverItem:Properties, whateverItem:Test etc.
Should the

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

return the 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧城空念 2024-12-03 02:46:32

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

Did you declare the 'whateverItem' namespace in the actual XML input? Try running your input through xmllint (a command-line utility in most Linux distros) to see if it picks up any problems, first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文