Insert XML data into database

Hello friends

I am working with xml and php and mysql…in this code i am inserting downloaded xml file into database…but the problem is with my xml file…eg…so plz help me…
<<<<XML FILE ON WHICH I HAVE TO WORK>>>>>
<root>
<patient>
<int_patient_id>56</int_patient_id>
<int_login_id>23</int_login_id>
<str_patient_salutation>8</str_patient_salutation>
<patient_insurance_plan>
<int_patient_insurance_plan_id>3</int_patient_insurance_plan_id>
<int_patient_login_id>2</<int_patient_login_id>
</patient_insurance_plan>
</patient>
</root>

but the code works only this type of file
<<<CODE WORKS ONLY FOR THIS FILE>>>
<patient>
<int_patient_id>56</int_patient_id>
<int_login_id>23</int_login_id>
<str_patient_salutation>8</str_patient_salutation>
</patient>
<patient_insurance_plan>
<int_patient_insurance_plan_id>3</int_patient_insurance_plan_id>
<int_patient_login_id>2</<int_patient_login_id>
</patient_insurance_plan>
</root>

<<<<WHOLE FILE CODE DOWN HERE>>>>

<?php

require_once "./PEAR/DB.php";

        
if ($_FILES["file"]["error"] &gt; 0)
{
    echo "Error: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
}
  else
{
    echo "Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;";
    echo "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
}

ini_set("max_execution_time",1000);

$strNewFileName = "xmlArrayTest1.xml";

if(!move_uploaded_file($_FILES["file"]["tmp_name"],'./'.$strNewFileName))
{
    $MYSQL_ERROR = "Error in moving the xml file";
    return 0;
}

class patientInfo
{
    var $insidePatient = false;
    var $insidePatientInsurancePlan = false;
   
    var $link, $tag, $strTableName, $strNewFileName, $strFieldName, $strFieldValue, $xml_parser, $patientResult;
    
    var $strLastPatientTag, $strLastPatientInsurancePlanTag ;
    
    function patientInfo($argLink)
    { 
        $this-&gt;link = $argLink;
        
        $this-&gt;xml_parser = xml_parser_create();
        
        xml_set_object($this-&gt;xml_parser, $this);
        
        xml_set_element_handler($this-&gt;xml_parser, "startElement", "endElement");

        xml_set_character_data_handler($this-&gt;xml_parser, "characterData");
    } 
    
    function startElement($parser, $name, $attrs) 
    {    
        if ($this-&gt;insidePatient) 
        {
            $this-&gt;tag = $name;
        } 
        elseif ($name == "PATIENT") 
        {
            $this-&gt;insidePatient = true;
            
            $this-&gt;strTableName = "tbl_patient";
        }
        
        if ($this-&gt;insidePatientInsurancePlan) 
        {
            $this-&gt;tag = $name;
        } 
        elseif ($name == "PATIENT_INSURANCE_PLAN") 
        {
            $this-&gt;insidePatientInsurancePlan = true;
            
            $this-&gt;strTableName = "tbl_patient_insurance_plan";
        }
    }

    function endElement($parser, $name) 
    {
        if ($name == "PATIENT") 
        {                        
            $this-&gt;patientResult = $this-&gt;savePatientInfo();
        
            $this-&gt;strFieldName="";
            
            $this-&gt;strFieldValue="";
            
            $this-&gt;strTableName="";

            $this-&gt;insidePatient = false;
        }
        
        if ($name == "PATIENT_INSURANCE_PLAN") 
        {                        
            $this-&gt;patientInsurancePlanResult = $this-&gt;savePatientInfo();
        
            $this-&gt;strFieldName="";
            
            $this-&gt;strFieldValue="";
            
            $this-&gt;strTableName="";

            $this-&gt;insidePatientInsurancePlan = false;
        }
    }
    
    function savePatientInfo()
    {    
        $query = "INSERT INTO ".$this-&gt;strTableName."(".$this-&gt;strFieldName.") ".
            "VALUES (".$this-&gt;strFieldValue.")";
        echo "&lt;br&gt;";
        echo $query;
        mysql_query($query) or die('Error, query failed');
    }
    
    function characterData($parser, $data) 
    {    
        if ($this-&gt;insidePatient && $this-&gt;strLastPatientTag != $this-&gt;tag ) 
        { 
            switch ($this-&gt;tag) 
            {
                case "INT_PATIENT_ID":
                    $this-&gt;strFieldName.= "int_patient_id,";
                    $this-&gt;strFieldValue.= $this-&gt;link-&gt;nextId('patientIdSequence').",";
                    break;
                
                case "INT_LOGIN_ID":
                    $this-&gt;strFieldName.= "int_login_id,";
                    $this-&gt;strFieldValue.= $this-&gt;link-&gt;nextId('loginIdSequence').",";
                    break;
                                        
                case "STR_PATIENT_SALUTATION":
                    $this-&gt;strFieldName.= "str_patient_salutation";
                    $this-&gt;strFieldValue.= "\"".$data."\"";
                    break;
            }
            echo "&lt;BR&gt;"; 
        }
        $this-&gt;strLastPatientTag = $this-&gt;tag;
        
        if ($this-&gt;insidePatientInsurancePlan && $this-&gt;strLastPatientInsurancePlanTag != $this-&gt;tag ) 
        { 
            switch ($this-&gt;tag) 
            {
                case "INT_PATIENT_INSURANCE_PLAN_ID":
                    $this-&gt;strFieldName.= "int_patient_insurance_plan_id,";
                    $this-&gt;strFieldValue.= $this-&gt;link-&gt;nextId('patientInsurancePlanIdSequence').",";    
                    break;
                case "INT_PATIENT_LOGIN_ID":
                    $this-&gt;strFieldName.= "int_patient_login_id,";
                    $this-&gt;strFieldValue.= $this-&gt;link-&gt;nextId('patientLoginIdSequence').",";
                    break;
                
                case "INT_INSURANCE_PLAN_ID":
                    $this-&gt;strFieldName.= "int_insurance_plan_id";
                    $this-&gt;strFieldValue.= $this-&gt;link-&gt;nextId('insurancePlanIdSequence')."";
                    break;
            }
            echo "&lt;BR&gt;"; 
        }
        $this-&gt;strLastPatientInsurancePlanTag = $this-&gt;tag;
    }    
                                    
    function readPatientInfo($argStrNewFileName)
    {        
        $fp = fopen($argStrNewFileName,"r") or die("Error reading RSS data.");
        
        while ($data = fread($fp, filesize($argStrNewFileName)))
        {
            xml_parse($this-&gt;xml_parser, $data, feof($fp));
            
            fclose($fp);
            
            xml_parser_free($this-&gt;xml_parser);
            
            $this-&gt;link-&gt;disconnect() or die("Can not close the database.");
        }
    }    
    /*function dbClose($link)
    {   
        $link-&gt;disconnect() or die("Can not close the database.");
    }*/
}


$dbName = "testdb";
$dbHost = "localhost";
$dbUser = "test";
$dbPassword = "test";

$dsn = "mysql://$dbUser:$dbPassword@$dbHost/$dbName";

$link = DB::connect($dsn);

if (DB::isError($link)) 
{    
    die ($link-&gt;getMessage());
}

$patientInfoResult = new patientInfo($link);

$patientInfoResult-&gt;readPatientInfo($strNewFileName);

?>