Posts: 115
Location: in the interwebz
|
hello all,
I am working on a script to open xml file, and find certain conditions and correct the information under those conditions. My code is rather junky and unoptimized at the moment, while I get the process down.
PHP Code:
<?php $file = "contactLast.xml";
function contents($parser, $data){ //information is in this area $info = $data;
if ($info == "Hewlett-Packard Company") { correct(); } else { $handle = fopen('XXX.xml', 'a'); $text = $info; fwrite($handle, $text); } }
function correct() { $handle = fopen('XXX.xml', 'a'); $text = 'Next'; fwrite($handle, $text); }
function startTag($parser, $data){ $handle = fopen('XXX.xml', 'a'); $text = $data; fwrite($handle, $text); } function endTag($parser, $data){ $handle = fopen('XXX.xml', 'w'); $text = $data; fwrite($handle, $text); }
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp = fopen($file, "r");
$data = fread($fp, 2000000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){ die("Error on line " . xml_get_current_line_number($xml_parser)); }
xml_parser_free($xml_parser);
fclose($fp);
?>
Here is a sample of my xml file
Code:
<?xml version="1.0"?>
<row>
<Cell ss:StyleID="s73"><Data ss:Type="String">Service</Data></Cell>
<Cell ss:StyleID="s73"><Data ss:Type="String">Status</Data></Cell>
<Cell ss:StyleID="s73"><Data ss:Type="String">Body</Data></Cell>
<Cell ss:StyleID="s73"><Data ss:Type="String">Officer</Data></Cell>
<Cell ss:StyleID="s73"><Data ss:Type="String">Service</Data></Cell>
<Cell ss:StyleID="s73"><Data ss:Type="String">Status</Data></Cell>
</row>
<row>
<Row>
<Cell ss:StyleID="s77"/><Data ss:Type="String">Info Here</Data>
<Cell ss:StyleID="s77"/><Data ss:Type="String">Info Here</Data>
<Cell ss:StyleID="s77"/><Data ss:Type="String">Info Here</Data>
<Cell ss:StyleID="s77"/><Data ss:Type="String">Info Here</Data>
<Cell ss:StyleID="s77"/><Data ss:Type="String">Info Here</Data></Cell>
<Cell ss:StyleID="s77"><Data ss:Type="String">Member</Data></Cell>
</row>
Its not done in a "conventional" xml fashion. How do I go about doing this? I am trying to write the new information back to a new xml file, or would it be better to write it back to the same one?
Last edited by rezzy; 05-13-2009 at 05:11 PM..
|