parse XML into mysql

This is a discussion on parse XML into mysql within the PHP Language forums, part of the PHP Programming Forums category; Hi i have an XML like this: <?xml version="1.0" encoding="ISO-8859-1" ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-25-2008
sandro
 
Posts: n/a
Default parse XML into mysql

Hi
i have an XML like this:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<parlast modified="20/06/2008 12:03">
<nodo name="test" nodoid="3893">
<group name="test2 groupid="12322">
<event name="test3" eventid="6939592"
closetime="21/06/2008 02:15">
<dettagli name="PRIMO DETTAGLIO"
dettagliid="6939592" etid="10">
<ok="1xxxxxxxx" id="34494265"
prezzo="1.70" status="Open"/>
<ok="2xxxxxxxx" id="34494266"
prezzo="3.30" status="Open"/>
<ok="3xxxxxxxx" id="34494267"
prezzo="4.50" status="Open"/>
</dettagli>
<dettagli name="SECONDO DETTAGLIO"
dettagliid="6939595"
etid="120">
<ok="4xxxxxxxx" id="34494274"
prezzo="2.20" status="Open"/>
<ok="5xxxxxxxx" id="34494275"
prezzo="2.15" status="Open"/>
<ok="6xxxxxxxx" id="34494276"
prezzo="4.50" status="Open"/>
</dettagli>
</event>
</group>
</nodo>
</parlast>

i should insert a specific data into mysql db

i used some classes e function ( simple xml , xml to array ecc.ecc )
but i failed

Some of you have already made this issue?


################################################## ##################
here it's my code
<?php


class Parser {


var $struct = array(); // holds final structure
var $curptr; // current branch on $struct
var $parents = array(); // parent branches of current branch


function Parser($url) {
$this->curptr =& $this->struct; // set ref to base
$xmlparser = xml_parser_create();
xml_set_object($xmlparser, $this);
xml_set_element_handler($xmlparser, 'tag_open', 'tag_close');
xml_set_character_data_handler($xmlparser, 'cdata');
$fp = fopen($url, 'r');


while ($data = fread($fp, 4096))
xml_parse($xmlparser, $data, feof($fp))
|| die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xmlparser)),
xml_get_current_line_number($xmlparser)));


fclose($fp);
xml_parser_free($xmlparser);
}


function tag_open($parser, $tag, $attr) {
$i = count($this->curptr['children']);
$j = count($this->parents);
$this->curptr['children'][$i]=array(); // add new child element
$this->parents[$j] =& $this->curptr; // store current position
as
parent
$this->curptr =& $this->curptr['children'][$i]; // submerge to
newly created child element
$this->curptr['name'] = $tag;
if (count($attr)>0) $this->curptr['attr'] = $attr;


}


function tag_close($parser, $tag) {
$i = count($this->parents);
if ($i>0) $this->curptr =& $this->parents[$i-1]; // return to
parent element
unset($this->parents[$i-1]); // clear from list of parents
}


function cdata($parser, $data) {
$data = trim($data);
if (!empty($data)) {
$this->curptr['value'] .= $data;
}
}



}


$myparser = new Parser('xml.xml');

print_r($myparser->struct);


################################################## ##################

thx



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:29 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0