With this XML:
<?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>
Code:
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;
}
Why it prints out databases 5 times? I call get('/databases') ... Thank you.