The concept is to search and display the data stored in a XML file using PHP+ XMLDOM+ JavaScript.(Sorry for bad English guys).
Index.php
The search is done using 3 types of values where JavaScript+XMLDOM is used to get the XML elements from the XML file and do dynamic loading of those values into ComboBox.
var selvalue = selprov.options[selprov.selectedIndex].value
var xmldoc = new ActiveXObject("Microsoft.XMLDOM")
xmldoc.async = false
xmldoc.load("REGION.xml")
var Elem = xmldoc.getElementsByTagName("PROVINCE") ;
Provlength = Elem.length;
for(i=0;i<=(Provlength-1);i++)
{
var prov = Elem.item(i).attributes.getNamedItem("NAME").text;
if (prov == selvalue)
{
var RegElem = Elem.item(i).getElementsByTagName("REGION") ;
Reglength = RegElem.length;
for(i=0;i<=(Reglength-1);i++)
{
region = RegElem.item(i).attributes.getNamedItem("NAME").text;
var ToCombo = document.frmcgo.selreg;
var addtext=region;
var addvalue=region;
ToCombo.options[i]=new Option(addtext,addvalue);
}
}
}
}
function changedest(selreg,selprv)
{
var NodeList
var destination = new Array()
var selvalue = selreg.options[selreg.selectedIndex].value
var xmldoc = new ActiveXObject("Microsoft.XMLDOM")
xmldoc.async = false
xmldoc.load("REGION.xml")
var Elem = xmldoc.getElementsByTagName("PROVINCE") ;
Provlength = Elem.length;
for(i=0;i<=(Provlength-1);i++)
{
var prov = Elem.item(i).attributes.getNamedItem("NAME").text;
if (prov == selprv)
{
var RegElem = Elem.item(i).getElementsByTagName("REGION") ;
Reglength = RegElem.length;
for(j=0;j<=(Reglength-1);j++)
{
var reg = RegElem.item(j).attributes.getNamedItem("NAME").text;
if (reg == selvalue)
{
var DestElem = RegElem.item(j).getElementsByTagName("DESTINATION") ;
Destlength = DestElem.length;
for(k=0;k<=(Destlength-1);k++)
{
destination = DestElem.item(k).text;
var ToCombo = document.frmcgo.seldest;
var addtext=destination;
var addvalue=destination;
for ($x=0; $x<sizeof($province); $x++)
{
if ($province[$x]->type == XML_ELEMENT_NODE) //PROVINCE -- if empty dont show index
{
$attributes = $province[$x]->attributes();
if (is_array($attributes) && ($index = is_list_attribute_present($attributes)))
{
$provlist[] = $index;
$region = $province[$x]->children();
for ($y=0; $y<sizeof($region); $y++)
{
if ($region[$y]->type == XML_ELEMENT_NODE) //REGION
{
$attributes = $region[$y]->attributes();
if (is_array($attributes) && ($index = is_list_attribute_present($attributes)))
{
$reglist[] = $index;
$dest = $region[$y]->children();
RateList.php
It collects the form values from the Index.php and browse thru the XML file using PHP+XMLDOM and display it as a Table(different than ordinary table).
<html>
<head></head>
<basefont face="Arial">
<TITLE>XML Data Display using PHP+DOM+JavaScript</TITLE>
for ($x=0; $x<sizeof($provchild); $x++)
{
if ($provchild[$x]->type == XML_ELEMENT_NODE) //PROVINCE -- if empty dont show index
{
$attributes = $provchild[$x]->attributes();
if (is_array($attributes) && ($index = is_province_attribute_present($attributes, $attvalprov)))
{
//-------------------------------------------------
$regchild = $provchild[$x]->children();
for ($y=0; $y<sizeof($regchild); $y++)
{
if ($regchild[$y]->type == XML_ELEMENT_NODE) //REGION
{
$attributes = $regchild[$y]->attributes();
if (is_array($attributes) && ($index = is_region_attribute_present($attributes, $attvalreg)))
{
Jose Santos wrote :1039
It`s an alternative that output data to XML.
Another good ideia is to use the XML_Tree package of the pear of php (see http://pear.php.net/manual/en/package.xml.xml-tree.php). It`s very simple and easy to use. With XML_Tree, don`t need close XML tag, the XML_Tree close tags automatically. It`s has an hierarchy of nodes.
Jose Santos wrote :1040
It`s an alternative that output data to XML.
Another good ideia is to use the XML_Tree package of the pear of php (see http://pear.php.net/manual/en/package.xml.xml-tree.php). It`s very simple and easy to use. With XML_Tree, don`t need close XML tag, the XML_Tree close tags automatically. It`s has an hierarchy of nodes.