【发布时间】:2010-12-25 06:04:50
【问题描述】:
我必须用 PHP 将一个 xml 文件解析为一个对象。目前我不知道如何执行此操作,不胜感激。
xml 很大。我必须解析它的一部分,如下所示:
<someNamespace:xmlDocument>
<someNamespace:categories>
<category name="Patrick" anAttribute="numericValue" anotherAttribute="numericValue">
<category name="Andrew" anAttribute="numericValue" anotherAttribute="numericValue">
<category name="Alice" anAttribute="numericValue" anotherAttribute="numericValue">
<category name="Thomas" anAttribute="numericValue" anotherAttribute="numericValue">
<category name="Michael" anAttribute="numericValue" anotherAttribute="numericValue"/>
<category name="Matthew" anAttribute="numericValue" anotherAttribute="numericValue"/>
</category>
<category name="Janet" anAttribute="numericValue" anotherAttribute="numericValue">
<category name="Steven" anAttribute="numericValue" anotherAttribute="numericValue"/>
<category name="Christopher" anAttribute="numericValue" anotherAttribute="numericValue"/>
</category>
<category name="Sue" anAttribute="numericValue" anotherAttribute="numericValue"/>
</category>
<category name="Charles" anAttribute="numericValue" anotherAttribute="numericValue">
<category name="John" anAttribute="numericValue" anotherAttribute="numericValue">
<category name="Charles" anAttribute="numericValue" anotherAttribute="numericValue"/>
<category name="Rosamund" anAttribute="numericValue" anotherAttribute="numericValue"/>
<category name="Stuart" anAttribute="numericValue" anotherAttribute="numericValue"/>
<category name="Rosamund" anAttribute="numericValue" anotherAttribute="numericValue"/>
</category>
<category name="John" anAttribute="numericValue" anotherAttribute="numericValue"/>
</category>
</category>
<category name="Oliver" anAttribute="numericValue" anotherAttribute="numericValue">
<category name="Jane" anAttribute="numericValue" anotherAttribute="numericValue"/>
<category name="Lucy" anAttribute="numericValue" anotherAttribute="numericValue">
<category name="David" anAttribute="numericValue" anotherAttribute="numericValue"/>
<category name="Robert" anAttribute="numericValue" anotherAttribute="numericValue"/>
<category name="Hetty" anAttribute="numericValue" anotherAttribute="numericValue">
<category name="Kenneth" anAttribute="numericValue" anotherAttribute="numericValue"/>
<category name="Jonathan" anAttribute="numericValue" anotherAttribute="numericValue"/>
</category>
<category name="Freddy" anAttribute="numericValue" anotherAttribute="numericValue"/>
<category name="Virginia" anAttribute="numericValue" anotherAttribute="numericValue"/>
</category>
</category>
</category>
</someNamespace:categories>
每个“name”和“anAttribute”属性都是唯一的。
之后我想要的是一个包含许多类别对象的类别对象......
谢谢!
【问题讨论】: