我想使用simplephp循環訪問xml文件。xml解析具有特殊條件的循環
我的訪問代碼是這樣的:
// get the path of the file
$file = "xml/".$item_name . "_cfg.xml";
if(! $xml = simplexml_load_file($file)){
echo 'unable to load XML file';
} else {
$item_array = array();
foreach($xml->config->exported->item as $items)
{
$item_name = (string) $items->attributes()->name;
echo "item name: " . $item_name . "<br />";
}
這將回聲出在該XML的所有項名稱的名稱,因爲一些數據是敏感的,但它基本上是這樣的心不是實際的XML與不同的數據一樣。
所以它會顯示爲基於下面的XML如下:
yellow
blue
orange
red
black
這裏是XML
<?xml version="1.0"?>
<main>
<config>
<exported>
<items>
<item name="yellow"></item>
<item name="blue"></item>
<New_Line />
<item name="orange"></item>
<item name="red"></item>
<New_Line />
<item name="black"></item>
</items>
</exported>
</config>
<main>
都很好,但我需要顯示的是:
yellow
blue
--------
orange
red
--------
black
如果你在xml中注意到這個行之間有一些數據
<New_Line />
當我遇到我想呼應的幾個短線,但我真的不知道你是怎麼做的,因爲我不太熟悉的SimpleXML