Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
parse and write data to xml
Old 05-13-2009, 05:05 PM parse and write data to xml
rezzy's Avatar
Super Talker

Posts: 115
Location: in the interwebz
Trades: 0
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($fp2000000);

if(!(
xml_parse($xml_parser$datafeof($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?
__________________

Please login or register to view this content. Registration is FREE

Resnodesigns

Last edited by rezzy; 05-13-2009 at 05:11 PM..
rezzy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to parse and write data to xml
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.08366 seconds with 12 queries