PHP的SimpleXML扩展提供了一个非常简单和易于使用的工具集,把XML转换为可以通过数组迭代的对象。
我们使用SimpleXML来加载XML文件如下。
sample.xml文件内容如下
<library>
<book>
<title>A</title>
<author gender="female">B</author>
<description>C</description>
</book>
<book>
<title>C</title>
<author gender="male">D</author>
<description>E</description>
</book>
<book>
<title>F</title>
<author gender="male">G</author>
<description>H</description>
</book>
</library>