<?xml version="1.0" encoding="UTF-8" ?>
<databases>
<default>
<type>mysql</type>
<host>localhost</host>
<table-prefix></table-prefix>
<username>root</username>
<password></password>
<charset>UTF-8</charset>
</default>
<test>
<type>mysql</type>
<host>localhost</host>
<table-prefix></table-prefix>
<username>root</username>
<password></password>
<charset>UTF-8</charset>
</test>
</databases>
コード:
public function get($xpath = '/')
{
$dom_object = new DOMDocument();
$dom_object->load($this->_filename);
$domxpath_object = new DOMXpath($dom_object);
$domnodelist_object = $domxpath_object->query($xpath);
return $this->XMLConfigurationToArray($domnodelist_object);
}
private function XMLConfigurationToArray(DOMNodeList $domnodelist_object)
{
$configuration_array = array();
foreach ($domnodelist_object as $element)
{
if ($element->hasChildNodes())
{
foreach ($element->childNodes as $c)
{
print_r('<pre>' . $element->tagName . '</pre>');
}
}
}
return $configuration_array;
}
それはデータベース5回をプリントアウトなぜ?私はget( '/ databases')を呼び出します... ありがとうございます。
"データベース"が2回表示されると思われますか? –
データベースは一度だけ間違っていますか? – thomas
*(関連)* http://stackoverflow.com/questions/4598409/printing-content-of-a-xml-file-using-xml-dom/4599724#4599724 – Gordon