Here's the task. I need to read the xml file below into a database. One row per defendant. However the xml file doesn't necessarily put all the defendants data on one row. The way I know how to parse xml with simplexml generated the following. 3 rows per defendant and now i'm trying to figure a way to merge the necessary data per row into one row, or somehow end up with one row per defendant.
Event Type: system
Event Time: 10:42:49
Length: 00:00:01
Start/Stop: Start Cap:10h42m48s.asf on 2011-04-19
Case Number:
Case Type:
Defendant 1:
Defendant 2:
Counselor 1:
Counselor 2:
Event Type: case
Event Time: 10:42:49
Length: 00:00:01
Start/Stop:
Case Number: GS534164
Case Type: GSPH
Defendant 1: Jeff Dearing
Defendant 2:
Counselor 1: Mike Engle
Counselor 2:
Event Type: system
Event Time: 10:59:12
Length: 00:16:24
Start/Stop: Stop Cap
Case Number:
Case Type:
Defendant 1:
Defendant 2:
Counselor 1:
Counselor 2:
Here is the actual xml file, I only used one defendant for the example above.
[/code]
And here is the xml file that I'm reading and trying to generate one row per defendant.
Hears the script that reads it into the database.
Event Type: system
Event Time: 10:42:49
Length: 00:00:01
Start/Stop: Start Cap:10h42m48s.asf on 2011-04-19
Case Number:
Case Type:
Defendant 1:
Defendant 2:
Counselor 1:
Counselor 2:
Event Type: case
Event Time: 10:42:49
Length: 00:00:01
Start/Stop:
Case Number: GS534164
Case Type: GSPH
Defendant 1: Jeff Dearing
Defendant 2:
Counselor 1: Mike Engle
Counselor 2:
Event Type: system
Event Time: 10:59:12
Length: 00:16:24
Start/Stop: Stop Cap
Case Number:
Case Type:
Defendant 1:
Defendant 2:
Counselor 1:
Counselor 2:
Here is the actual xml file, I only used one defendant for the example above.
[/code]
And here is the xml file that I'm reading and trying to generate one row per defendant.
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="log.xsl" type="text/xsl"?>
<log>
<header>
<title><![CDATA[2011-04-19-Turner]]></title>
<state><![CDATA[Tn]]></state>
<county><![CDATA[Davision]]></county>
<courtroom display="true"><![CDATA[]]></courtroom>
<courtSystem><![CDATA[General Sessions]]></courtSystem>
<department><![CDATA[Division 5]]></department>
<judge><![CDATA[Diane Turner]]></judge>
<clerk><![CDATA[Mike Walker]]></clerk>
<bailiff><![CDATA[]]></bailiff>
<logSuffix><![CDATA[Turner]]></logSuffix>
<logDate><![CDATA[2011-04-19]]></logDate>
<tapeNumber display="false"><![CDATA[]]></tapeNumber>
</header>
<event type="system" time="10:42:49" vcrTime="00:00:00" digitalTime="00:00:01" cvf="10h42m48s_00_00_01.cvf">
<text><![CDATA[Start Cap:10h42m48s.asf on 2011-04-19]]></text>
</event>
<event type="case" time="10:42:49" vcrTime="00:00:00" digitalTime="00:00:01" cvf="10h42m48s_00_00_01.cvf">
<case>
<caseId><![CDATA[GS534164]]></caseId>
<caseType><![CDATA[GSPH]]></caseType>
<party1><![CDATA[Jeff Dearing]]></party1>
<party2><![CDATA[]]></party2>
<counsel1><![CDATA[Mike Engle]]></counsel1>
<counsel2><![CDATA[]]></counsel2>
</case>
</event>
<event type="system" time="10:59:12" vcrTime="00:00:00" digitalTime="00:16:24" cvf="10h42m48s_00_16_24.cvf">
<text><![CDATA[Stop Cap]]></text>
</event>
<event type="system" time="11:15:50" vcrTime="00:00:00" digitalTime="00:00:01" cvf="11h15m49s_00_00_01.cvf">
<text><![CDATA[Start Cap:11h15m49s.asf on 2011-04-19]]></text>
</event>
<event type="case" time="11:15:50" vcrTime="00:00:00" digitalTime="00:00:01" cvf="11h15m49s_00_00_01.cvf">
<case>
<caseId><![CDATA[GS534491]]></caseId>
<caseType><![CDATA[GSPH]]></caseType>
<party1><![CDATA[James Guest]]></party1>
<party2><![CDATA[]]></party2>
<counsel1><![CDATA[Mike Engle]]></counsel1>
<counsel2><![CDATA[]]></counsel2>
</case>
</event>
<event type="system" time="11:57:14" vcrTime="00:00:00" digitalTime="00:41:25" cvf="11h15m49s_00_41_25.cvf">
<text><![CDATA[Stop Cap]]></text>
</event>
<event type="system" time="12:02:25" vcrTime="00:00:00" digitalTime="00:00:00" cvf="12h02m25s_00_00_00.cvf">
<text><![CDATA[Start Cap:12h02m25s.asf on 2011-04-19]]></text>
</event>
<event type="case" time="12:02:26" vcrTime="00:00:00" digitalTime="00:00:01" cvf="12h02m25s_00_00_01.cvf">
<case>
<caseId><![CDATA[GS532494]]></caseId>
<caseType><![CDATA[GSPH]]></caseType>
<party1><![CDATA[Jeremy Johnson]]></party1>
<party2><![CDATA[]]></party2>
<counsel1><![CDATA[Robert Turner]]></counsel1>
<counsel2><![CDATA[]]></counsel2>
</case>
</event>
<event type="system" time="12:33:26" vcrTime="00:00:00" digitalTime="00:31:01" cvf="12h02m25s_00_31_01.cvf">
<text><![CDATA[Stop Cap]]></text>
</event>
<event type="system" time="12:55:49" vcrTime="00:00:00" digitalTime="00:00:00" cvf="12h55m49s_00_00_00.cvf">
<text><![CDATA[Start Cap:12h55m49s.asf on 2011-04-19]]></text>
</event>
<event type="case" time="12:55:49" vcrTime="00:00:00" digitalTime="00:00:00" cvf="12h55m49s_00_00_00.cvf">
<case>
<caseId><![CDATA[GS534424]]></caseId>
<caseType><![CDATA[GSPH]]></caseType>
<party1><![CDATA[Samuel Lee & Johnathon Abernathy]]></party1>
<party2><![CDATA[Lacy Lyles]]></party2>
<counsel1><![CDATA[Mike Engle & Barry Gearon]]></counsel1>
<counsel2><![CDATA[Kyle Parks]]></counsel2>
</case>
</event>
<event type="system" time="01:33:24" vcrTime="00:00:00" digitalTime="00:37:35" cvf="12h55m49s_00_37_35.cvf">
<text><![CDATA[Stop Cap]]></text>
</event>
</log>
Hears the script that reads it into the database.
Code:
$xmlstr = file_get_contents($file);
$phLog = new SimpleXMLElement($xmlstr);
foreach($phLog->header as $headerInfo)
{
$hquery = "INSERT INTO ph_headers (`id`, `title`, `department`, `judge`, `clerk`, `logDate`) VALUES ('', '$headerInfo->title', '$headerInfo->department', '$headerInfo->judge', '$headerInfo->clerk', '$headerInfo->logDate')";
mysql_query($hquery)or die(mysql_error());
$hid = mysql_insert_id();
}
foreach($phLog->event as $eventInfo)
{
$caseId = $eventInfo->case->caseId;
$caseType = $eventInfo->case->caseType;
$party1 = $eventInfo->case->party1;
$party2 = $eventInfo->case->party2;
$counsel1 = $eventInfo->case->counsel1;
$counsel2 = $eventInfo->case->counsel2;
$dquery = "INSERT INTO ph_detail (`id`, `hid`, `caseId`, `caseType`, `party1`, `party2`, `counsel1`, `counsel2`, `length`, `startTime`, `stopTime`, `asfFileName`, `path`, `link`) VALUES ('', '$hid', '$caseId', '$caseType', '$party1', '$party2', '$counsel1', '$counsel2', '$eventInfo[digitalTime]', '$eventInfo->text', '$eventInfo->text', '$asfFileName', '$dp', '$link')";
mysql_query($dquery)or die(mysql_error());
}
Please someone, how would you do this?
Parse this xml and insert pertinent data into one row per defendant.
Thanks for any help.