0
我一直在使用PHP的簡單XML函數來處理XML文件。PHP - 簡單的XML - 嵌套層次
下面的代碼工作正常,一個簡單的XML層次結構:
$xml = simplexml_load_file("test.xml");
echo $xml->getName() . "<br />";
foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br />";
}
這是假設XML文檔的結構如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
但是,如果我有一個更復雜的結構在我的XML文檔中 - 內容不會被輸出。更復雜的XML示例如下所示:
<note>
<noteproperties>
<notetype>
TEST
</notetype>
</noteproperties>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
我需要處理具有無限深度的XML文件 - 任何人都可以提出一種方法嗎?