protected function callbackPrice($reader) { $xml = $reader->expandSimpleXml(); $attributes = $xml->attributes(); $ref = (string) $attributes->{"Номенклатура"}; if ($ref) { $price = floatval((string) $xml); $xpath = $this->currentXpath(); echo "{$xpath}: {$ref} = {$price};\n"; } return true; } protected function callbackRest($reader) { $xml = $reader->expandSimpleXml(); $attributes = $xml->attributes(); $ref = (string) $attributes->{"Номенклатура"}; if ($ref) { $rest = floatval((string) $xml); $xpath = $this->currentXpath(); echo "{$xpath}: {$ref} = {$rest};\n"; } return true; } } echo "<pre>"; $file = dirname(__FILE__) . "/example1.xml"; $reader = new ExampleXmlReader1(); $reader->open($file); $reader->parse(); $reader->close();
function runInteg(){ global $_FILES; $filename = (isset($_REQUEST['file']))?$_REQUEST['file']:''; create_import_tables(); if(isset($_FILES['xmlfile']['error']) && $_FILES['xmlfile']['error'] == 0){ $tmpname = $_FILES['xmlfile']['tmp_name']; $newname = $_SERVER['DOCUMENT_ROOT'].'/upload/'.$_FILES['xmlfile']['name']; echo $newname .'<br>'.$tmpname; if(is_file($newname)) @unlink($newname); // unset file is already exist same named copy($tmpname,$newname);// download new file $filename = $_FILES['xmlfile']['name']; // take file to parse } if(!empty($filename)): //умова виконяння персера $file = $_SERVER['DOCUMENT_ROOT'] . "/upload/".$filename; if(is_file($file)){ $reader = new ExampleXmlReader1($filename); $reader->open($file); $reader->parse(); $reader->close(); unset($reader); ///// global $array_obj; if(!empty($array_obj)){ $type = ''; if($filename == 'import.xml') $type = 'tovar'; if($filename == 'offers.xml') $type = 'price_type'; save_obj($array_obj,$type); } global $array_obj2; if(!empty($array_obj2)){ $type = ''; if($filename == 'offers.xml') $type = 'price_value'; save_obj($array_obj2,$type); } ///// } else { echo 'Помилка завантаження файлу'; }; endif; if(isset($_REQUEST['type']) && $_REQUEST['type'] == 'extract'){ if(!isset($_REQUEST['step'])){ //step 1: save groups import_save_groups(); echo '<script>window.location.href="/admin/admin.php?act=1c_integ&type=extract&step=2";</script>'; } if(isset($_REQUEST['step'])){ if($_REQUEST['step'] == 2){ //step 2: save tovars in catalog import_saving_tovars(); echo '<script>window.location.href="/admin/admin.php?act=1c_integ&type=extract&step=3";</script>'; } if($_REQUEST['step'] == 3){ //step 3: make price types array and add new users import_construct_price_types(); // connect price type code with user echo '<script>window.location.href="/admin/admin.php?act=1c_integ&type=extract&step=4";</script>'; } if($_REQUEST['step'] == 4){ // step 4: make item prices import_add_prices(); echo '<script>window.location.href="/admin/admin.php?act=1c_integ&type=extract&step=5";</script>'; } if($_REQUEST['step'] == 5){ //step 5: clear the tables clear_import_tables(); } } } ?> <h2>Виберите файл для загрузки</h2> <form enctype="multipart/form-data" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="80000000"> <input type="file" name="xmlfile" /> <input type="submit" value="загрузка" /> </form> <br /><br /> <i>Если нужен парсинг уже загруженого файла в папку '/upload/', передайте его имя в адресной строке (пример '/admin.php?act=1c_integ&file=filename')<i> <? }