Hello, I have an XML file thus -
<?xml version="1.0" encoding="iso-8859-1"?>
<magazine>
<gallery>
<image src="images/back" />
<image src="images/monstg" />
<image src="images/tuestg" />
<image src="images/wedstg" />
<image src="images/thustg" />
<image src="images/fristg" />
<image src="images/monhov"/>
<image src="images/tuehov"/>
<image src="images/wedhov"/>
<image src="images/thuhov"/>
<image src="images/frihov"/>
</gallery>
<color>
<image color="0x0F94CA" />
</color>
<monday>
<mon_txt1>montxt1</mon_txt1>
<mon_txt2>montxt2</mon_txt2>
<mon_txt3>montxt3</mon_txt3>
<url>monurl</url>
</monday>
<tuesday>
<tue_txt1>tuetxt1</tue_txt1>
<tue_txt2>tuetxt2</tue_txt2>
<tue_txt3>tuetxt3</tue_txt3>
<url>tueurl</url>
</tuesday>
<wednesday>
<wed_txt1>wedtxt1</wed_txt1>
<wed_txt2>wedtxt2</wed_txt2>
<wed_txt3>wedtxt3</wed_txt3>
<url>wurl</url>
</wednesday>
<thursday>
<thu_txt1>thutxt1</thu_txt1>
<thu_txt2>thutxt2</thu_txt2>
<thu_txt3>thutxt3</thu_txt3>
<url>thurl</url>
</thursday>
<friday>
<fri_txt1>fritxt1</fri_txt1>
<fri_txt2>fritxt2</fri_txt2>
<fri_txt3>fritxt3</fri_txt3>
<url>furl</url>
</friday>
</magazine>
Here's my PHP to read the XML
$xml_file = $mosConfig_absolute_path.'/gallery.xml';
$objDOM = new DOMDocument();
$objDOM->load($xml_file); //make sure path is correct
$xml['image'] = $objDOM->getElementsByTagName("gallery")->item(0);
$tasks = $xml['image']->getElementsByTagName("image");
foreach ($tasks as $task) {
$images[] = $task->getAttribute("src");
}
$xml['color'] = $objDOM->getElementsByTagName("color")->item(0);
$backs = $xml['color']->getElementsByTagName("image");
foreach ($backs as $back) {
$colors[] = $back->getAttribute("color");
}
$xml['mon'] = $objDOM->getElementsByTagName("monday")->item(0)->childNodes;
foreach ($xml['mon'] as $child) {
$days[] = $child->nodeValue;
}
$xml['tue'] = $objDOM->getElementsByTagName("tuesday")->item(0)->childNodes;
foreach ($xml['tue'] as $child) {
$days[] = $child->nodeValue;
}
$xml['wed'] = $objDOM->getElementsByTagName("wednesday")->item(0)->childNodes;
foreach ($xml['wed'] as $child) {
$days[] = $child->nodeValue;
}
$xml['thu'] = $objDOM->getElementsByTagName("thursday")->item(0)->childNodes;
foreach ($xml['thu'] as $child) {
$days[] = $child->nodeValue;
}
$xml['fri'] = $objDOM->getElementsByTagName("friday")->item(0)->childNodes;
foreach ($xml['fri'] as $child) {
$days[] = $child->nodeValue;
}
print_r($days);
The print_r function returns more values than i am expecting, It shows that the $days array has 44 values, it should only contain 20.
Any idea why this happens?