XML:通過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到所有節點itterate
到目前爲止,我可以這樣直接訪問節點:
$xmldata = simplexml_load_file("config.xml");
foreach($xmldata->Parameters as $item)
{
echo "<p>Version: " . $item->version . "</p>";
echo "<p>Site Folder: " . $item->siteFolder . "</p>";
}
但是這並不會使它成爲特定的根節點,而是會遍歷列表中的所有參數。我怎樣才能做到這一點?
可以請你詳細闡述「根節點特定」? – Makesh 2012-07-25 12:16:56
剛剛編輯它 - 以便你有特定的參數節點屬於它們各自的根節點: ex2 etc等 –
thejoker
2012-07-25 12:42:05