XML:
<?xml version="1.0" encoding="utf-8"?>
<NConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<NDomain>ex1</NDomain>
<Parameters>
<version>p</version>
<siteFolder>site1</siteFolder>
<cssGeneral></cssGeneral>
<cssLogin>l.css</cssLogin>
</Parameters>
<Database>
<hostname>898</hostname>
<username>j</username>
<password>k</password>
<name>n</name>
</Database>
<NDomain>ex2</NDomain>
<Parameters>
<version>p</version>
<siteFolder>site1</siteFolder>
<cssGeneral></cssGeneral>
<cssLogin>l.css</cssLogin>
</Parameters>
<Database>
<hostname>898</hostname>
<username>j</username>
<password>k</password>
<name>n</name>
</Database>
</NConfig>
我想遍历 ex1 下的所有节点
到目前为止,我可以通过这样做直接访问节点:
$xmldata = simplexml_load_file("config.xml");
foreach($xmldata->Parameters as $item)
{
echo "<p>Version: " . $item->version . "</p>";
echo "<p>Site Folder: " . $item->siteFolder . "</p>";
}
但这并不能使其特定于根节点,而是会遍历列表中的所有参数。我怎样才能做到这一点?