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>
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在实际 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.