Looping through XML file

Having problem loop through nodes
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bobby101Author Commented:

      <customer id="000">
                  <street>45 Olive Dr</street>
                  <date dt="29/11/2008">
                        <payDate>new acc</payDate>
                        <amtPaid> </amtPaid>
                  <date dt="28/02/2009">
                  <date dt="29/05/2009">
                  <date dt="29/08/2009">

Fatal error: Call to a member function getAttribute() on a non-object in C:\xampp\htdocs\dwax\billpayment.php on line 24

if (!$_SESSION['username']){
	header('Location: login.php');
$error = "";
	$target = $_POST['target']; 
	if(!$target == ""){
		$count = 0;
        $file = "files/customers.xml"; 
			  $doc = new DOMDocument();
			  $doc->load($file) or die('Unable to load file');
			  $node = $doc->getElementsByTagName('customer');
			  foreach( $node as $find ){
			  $id = $find->getAttribute('id');
					  if ($target == $id){
						$num = 0;
						$d = $doc->getElementsByTagName('dates')->item($count);
						while ($d){
						   $date = $d->getElementsByTagName('date')->item($num);
						   $dt = $date->getAttribute('dt');
						   echo $dt."<br />";
	//else if ($target == ""){$error="Unsuccessful";}	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<title>Energetic Energy Management</title>
	<h3>Welcome, <?php echo $_SESSION['username']; ?></h3>
	<a href="logout.php">Logout</a>
	<p>&raquo; <a href="index.php">Home</a>

<form name="search" method="post" action=""> 
<h3>Bill Payment</h3>
<p>Customer ID: <input type="text" name="target" size="20" /></p>
<input type="submit" value="Go" name="search" />
<p><span style="color:red;"><?php echo $error; ?></span></p>

Open in new window

Avinash ZalaWeb ExpertCommented:
Try attached code with your xml file, change the xml file name accordingly.

Hope this helps,
    $doc = new DOMDocument();

    $doc->load( $webroot.'/demo.xml' );

    $note = $doc->getElementsByTagName( "customer" );
    $final_arr = array();
    foreach($note as $note)
		$id = $note->getAttribute('id');

		$dates = $note->getElementsByTagName("dates");
        foreach($dates as $dates)
			$date = $dates->getElementsByTagName("date");
			foreach($date as $date)
				echo  $dated= $date->getAttribute('dt');
				 echo "<br/>";

Open in new window

bobby101Author Commented:
Sorry didnt work i its bring up the dates from other customer/s nodes as well.
basically how it should work is that you type in the customer id and brings up the billing date history of that customer i had it working but it also gives a error:
Fatal error: Call to a member function getAttribute() on a non-object in C:\xampp\htdocs\dwax\billpayment.php on line 24

HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

bobby101Author Commented:
output on browser:

Fatal error: Call to a member function getAttribute() on a non-object in C:\xampplite\htdocs\dwax\billpayment.php on line 24
Avinash ZalaWeb ExpertCommented:
i am not getting any error at all.

and which dates you want to get?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Components

From novice to tech pro — start learning today.