Attaining the child node values within the following Xml document, can some one show me what I am doing wrong I can navigate the XML document and return the values of the XML document but cant figure out how to return the child node values.
XML file :
<?xml version="1.0"?>
<dispatch>
<item>
<estamp>08-04-2006</estamp>
<project>X1800</project>
<dispatcher>andrew</dispatcher>
<docket>DCO1</docket>
<trailer_type>STD Oversize</trailer_type>
<trailer_rego>REGO 2345</trailer_rego>
<hotshot>YES</hotshot>
<loaded>
<loaditem>1162-1105-000A</loaditem>
<loaditem>1162-1105-000B</loaditem>
<loaditem>1162-1105-000C</loaditem>
<loaditem>1162-1105-000D</loaditem>
</loaded>
</item>
<item>
<estamp>01-04-2006</estamp>
<project>W1800</project>
<dispatcher>michael</dispatcher>
<docket>DOC123456</docket>
<trailer_type>STD Oversize</trailer_type>
<trailer_rego>REGO 123</trailer_rego>
<hotshot>YES</hotshot>
<loaded>
<loaditem>1158-1101-000A</loaditem>
<loaditem>1158-1101-000B</loaditem>
</loaded>
</item>
</dispatch>
php Code:
<?php
$dom = new DomDocument();
$dom->load("http://localhost/dispatch.xml");
$dom->preserveWhiteSpace = false;
$dispatched = $dom->documentElement;
$loaded = $dispatched->childNodes;
$i=-1;
$dispatch = $dispatched->getElementsByTagName("item");
foreach($dispatch as $item){
$nodeArray = array();
$i++;
$estamp = $dispatched->getElementsByTagName("estamp");
$entrydate = $estamp->item($i)->nodeValue;
$project = $dispatched->getElementsByTagName("project");
$projectno = $project->item($i)->nodeValue;
$dispatcher = $dispatched->getElementsByTagName("dispatcher");
$dispatchername = $dispatcher->item($i)->nodeValue;
$docket = $dispatched->getElementsByTagName("docket");
$docketno = $docket->item($i)->nodeValue;
$trailer_type = $dispatched->getElementsByTagName("trailer_type");
$trailertype = $trailer_type->item($i)->nodeValue;
$trailer_rego = $dispatched->getElementsByTagName("trailer_rego");
$trailerrego = $trailer_rego->item($i)->nodeValue;
$hotshot = $dispatched->getElementsByTagName("hotshot");
$hots = $hotshot->item($i)->nodeValue;
$a=-1;
$j=-1;
echo "$entrydate-$projectno-$dispatchername-$docketno-<BR>";
foreach ($loaded as $load) {
$a++;
$j++;
echo $load->item($a)->nodeValue;
echo $j."<br>";
}
echo "FINISHED READ ON<BR>";
}
?>