Hi all,

I have the following php script:

<?php

$doc = new DOMDocument();
  $doc->load( 'events.xml' );
  $events = $doc->getElementsByTagName( "event" );

  foreach( $events as $event)
 {
  $hours = $event->getElementsByTagName( "hour" );
  $hour = $hours->item(0)->nodeValue;

  $minutes = $event->getElementsByTagName( "minute" );
  $minute = $minutes->item(0)->nodeValue;

.
.
.
?>

events.xml contains schedules and info for events.

If an event is taking place now the php script will show a div with information. This chapter is done and working, the trouble comes with the xml load part.

If the load of the xml document is done only once (when the page is first time loaded), I will need to refresh the php script so it looks for more times and info ..but the user will see the page reloading all the time.

I need the php script to look for the events' times in the xml file at all times, so I guess I have to do an auto refreshing of the

$doc->load( 'events.xml' );

how can I do that??

Thanks a ton in advance!

Since i cannot run any test using PHP, i'll just provide you a basic demo using XMLHttpRequest() object, to deal with the current issue.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>AJAX Demo</title>

<script type="text/javascript">
// <![CDATA[

var autoUpdate, xmlData, loadXMLData, update, eventsXML;

update = function() {
   if ( xmlData.readyState == 4 ) {
   if ( xmlData.status == 200 ) {
events = xmlData.responseXML.getElementsByTagName("event"); 
      for ( var event in events ) {
alert(event + ": All data has been updated!");
// and the rest of the code continue -->
         }         
      }
   }
}

loadXMLData = function( url ) {
xmlData = null;
   if ( window.XMLHttpRequest ) {
         xmlData = new XMLHttpRequest();
   } 
   else if ( window.ActiveXObject ) {
      try {
         xmlData = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch( e ) {
          xmlData = new ActiveXObject("Msxml2.XMLHTTP");
      }
   }
   if ( xmlData !== null ) {
      xmlData.onreadystatechange = update; 
      xmlData.open("GET", url, true);
      xmlData.send( null );
   } 
   else {
      alert("\nYour browser does not support AJAX Request!"); 
   } 
};

window.onload = function() { autoUpdate = setInterval('loadXMLData("events.xml")', 10000); // This will perform an auto update in your request, every 10sec.
 };

// ]]>
</script>
</head>
<body>
<div id="content">



</div>  
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.