bubu Posted November 3, 2006 Report Share Posted November 3, 2006 To sauc par SAX, nevis "ar handleri", Delfin :) Link to comment Share on other sites More sharing options...
Delfins Posted November 3, 2006 Report Share Posted November 3, 2006 A tu domā viņš tādu terminu sapratīs `SAX` (sako) ? :) /kas pat nav minēts manuāli, ka tas ir SAX principā/ Es viņam dodu tiešo hintu, kur manuālī(komentos) ir 100% exampli šādiem darbiem. Link to comment Share on other sites More sharing options...
ffgghh Posted November 3, 2006 Author Report Share Posted November 3, 2006 Šķiet ka jūs par mani esat īpaši augstās domās!!! Bet vai šis ir pats ātrākais veidz kā iebāzt datus MySQL ??? require_once 'xml_saxy_parser.php'; $saxparser =& new SAXY_Parser(); $saxparser->xml_set_element_handler("startElementHandler", "endElementHandler"); $saxparser->xml_set_character_data_handler("characterHandler"); $npk="0"; $myXML = implode("",file("xml_y.xml")); $success = $saxparser->parse($myXML); if ($success) { echo "\n<br /><br />Parsing successful!"; echo ShowArray($DATA, "array"); } else { $errorCode = $saxparser->xml_get_error_code(); $errorString = $saxparser->xml_error_string($errorCode); echo "\n<br /><br />Error Code: " . $errorCode; echo "\n<br />Error String: " . $errorString; } function startElementHandler($parser, $elementName, $attrArray) { GLOBAL $npk, $DATA, $DATA_NAME; $DATA_NAME=$elementName; if($elementName!="VFPData"){ if($elementName=="klients"){if(isset($npk)){$npk++;}else{$npk=1;} }else{$DATA[$npk][$elementName]="";} } } function endElementHandler($parser, $elementName) {} function characterHandler($parser, $text) { GLOBAL $npk, $DATA, $DATA_NAME; if($DATA_NAME!="VFPDATA"&&$DATA_NAME!="KLIENTS"){ $DATA[$npk][$DATA_NAME]=$DATA[$npk][$DATA_NAME].$text; } } STARPCITU - tas SAXy izpildās lēnāk nekā: require_once 'XML/Parser.php'; class myParser extends XML_Parser { function myParser() {parent::XML_Parser();} function startHandler($xp, $name, $attribs) {GLOBAL $npk, $DATA, $DATA_NAME; $DATA_NAME=$name; if($name!="VFPDATA"){ if($name=="KLIENTS"){if(isset($npk)){$npk++;}else{$npk=1;} }else{$DATA[$npk][$name]="";} } } function endHandler($xp, $name){} function cdataHandler($xp, $cdata) {GLOBAL $npk, $DATA, $DATA_NAME; if($DATA_NAME!="VFPDATA"&&$DATA_NAME!="KLIENTS"){ $DATA[$npk][$DATA_NAME]=$DATA[$npk][$DATA_NAME].$cdata; } } } /*############################################################################################################*/ $p = &new myParser(); $result = $p->setInputFile('xml_1.xml'); $result = $p->parse(); echo ShowArray($DATA, "array"); Link to comment Share on other sites More sharing options...
Delfins Posted November 3, 2006 Report Share Posted November 3, 2006 Da tu ko... murgs.. $myXML = implode("",file("xml_y.xml")); Kam tev izmantot visādas neznāmas klases... Es takš tev teicu PHP manuālī ir piemērs, kā in-direct nopārsēt XML un apstrādāt to... blin, ku cilvēki mēdz būt ietiepīgi. Link to comment Share on other sites More sharing options...
Delfins Posted November 3, 2006 Report Share Posted November 3, 2006 (edited) <?php $file = "mans.xml"; $record = null; function startElement($xml_parser, $attrs ) { global $record; if ($attrs=='RECORD') { $record = null; } } function endElement($xml_parser, $name) { global $info; global $record; if ($name == 'RECORD') { print "DO_INSERT_".print_r($record,1)."<br />\n"; } else { $record->$name = $info; } $info = ""; } function charData($xml_parser, $data ) { global $info; $info .= $data; } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "charData"); $fp = fopen($file, "r"); while ($data = fread($fp, 1024)) { xml_parse($xml_parser, $data, feof($fp)); } xml_parser_free($xml_parser); ?> <?xml version="1.0"?> <table name="mana_tabula"> <record> <field1>Data 1</field1> <field2>Data 2</field2> </record> </table> Un vispār, šadas lietas jādara ar kādu zemāku valodu.. piem uzrakstīt konsoles tūli XML_to_inserts.exe un tad iebarot jau gatavus insertus Edited November 3, 2006 by Delfins Link to comment Share on other sites More sharing options...
ffgghh Posted November 3, 2006 Author Report Share Posted November 3, 2006 HMM, Liels paldies... Vispār par to zemākas valodas tūli būs jāpadomā! tikai exe man neder - man linux... Moš perl... /netīšam nezini vai kas jau nav daudzmaz gatavs pieejams?/ Liels paldies. Link to comment Share on other sites More sharing options...
Delfins Posted November 3, 2006 Report Share Posted November 3, 2006 Kāda starpība, kas par OS... Raksti uz C, un laid jebkur, ka tik būtu nokompilēts attiecīgi. Link to comment Share on other sites More sharing options...
PheliX Posted November 3, 2006 Report Share Posted November 3, 2006 http://www.php.net/manual/en/ref.xmlreader.php Link to comment Share on other sites More sharing options...
Recommended Posts