bubu Posted June 16, 2007 Report Share Posted June 16, 2007 error_reporting(E_ALL); ini_set('display_errors', 1); Padomā par to, ko dara otrais cikls - pa ko viņš iterē un kādus datus apstaigāt vajag. Link to comment Share on other sites More sharing options...
SadDemon Posted June 18, 2007 Author Report Share Posted June 18, 2007 Sakarā ar php 5 versijas dom funkcijas pārveidošanu par php 4 domxml.. Uz hostinga, kur testējuir php versija 4.4.1 (phpInfo); *.php saturs ir: $doc = domxml_new_doc('1.0'); $doc -> domxml_open_file('../xml/depot.xml'); $el = $doc -> get_elements_by_tag_name('product'); foreach($el as $element) { if($element -> get_attribute('id') == $id) { $element -> parent_node -> remove_child($element); break; } } $doc -> dump_file("../xml/depot.xml", false, false); Esmu pētījis php manuāli.. bet tik un tā ir kļūda - "Fatal error: Call to undefined function: domxml_new_doc() .... on line 5"; Vai kļūdos?.. vadoties pēc php manuāļa ir jādarbojas.. vai problēma ir php konfigurācijā uz hostinga, jo nemanu tur DomXml? Link to comment Share on other sites More sharing options...
v3rb0 Posted June 18, 2007 Report Share Posted June 18, 2007 negribu iedziļināties, bet --disable-xml pie configure command izskatās aizdomīgi. tāpat paziņojums par nedefinētu f-ju ir tad, kad tiešām tāda f-ja nava. phpinfo() burtu salikums "dom" vispār nefigurē. es teiktu, ka servera pusē kaut kas vēl trūkst. Link to comment Share on other sites More sharing options...
Paulinjsh Posted June 18, 2007 Report Share Posted June 18, 2007 jā, nav uzlikts Link to comment Share on other sites More sharing options...
SadDemon Posted June 18, 2007 Author Report Share Posted June 18, 2007 Vai ir kāda iespēja k-ko labot, mainīt vai pievienot servera uzstādījumos? Vai arī man jāatsakās no Dom metodes? Link to comment Share on other sites More sharing options...
SadDemon Posted June 18, 2007 Author Report Share Posted June 18, 2007 (edited) ..un skatamies serveris.lv phpInfo - pēc vārda "dom" neko neatrod.. un pēc vārda "xml" atrodam, ka xml support - active; Vai tas nozīmē, ka dom funkcijas nedarbosies? Edited June 18, 2007 by SadDemon Link to comment Share on other sites More sharing options...
bubu Posted June 18, 2007 Report Share Posted June 18, 2007 Tur ir aktivēts tikai SAX parsēšanas funkcijas izmantojot expat: http://lv2.php.net/xml DOM parsēšana tur nav aktivēta. Link to comment Share on other sites More sharing options...
SadDemon Posted June 20, 2007 Author Report Share Posted June 20, 2007 ..tad nu atgriežamies pie Dom metodes; esmu ticis galā ar ksort(); metodi.. *.php saturs: <?php $doc = new DOMDocument; $doc -> load('../xml/depot.xml'); $content = array(); $products = $doc -> getElementsByTagName('product'); foreach ($products as $product) { $id = $product -> getAttribute('id'); $amount = $product -> getAttribute('amount'); $name = $product -> getAttribute('name'); $color = $product -> getAttribute('color'); $article = $product -> getAttribute('article'); $category = $product -> getAttribute('category'); $status = $product -> getAttribute('status'); $row = "<"."product id=\"".$id."\" amount=\"".$amount."\" name=\"".$name."\" color=\"".$color."\" article=\"".$article."\" category=\"".$category."\" status=\"".$status."\" />"."<br>"; $content[$id] = $row; } ksort($content); foreach ($content as $output) { echo $output; } ?> ..un jautājums ir, kā jaunos (sakārtotos) datus varētu ierakstīt *.xml failā? Iepriekš izmantoju šādu skriptu: <?php // .. postētās variables $myXML = "../xml/depot.xml"; $ending = "</Noliktava>"; $content = file_get_contents($myXML); $content = substr($content, 0, strpos($content, $ending)-1); $newData = " <product id=\"".$id."\" amount=\"".$amount."\" name=\"".$name."\" color=\"".$color."\" article=\"".$article."\" category=\"".$category."\" status=\"".$status."\" /> ".$ending; $content.=$newData; $fHandle = fopen($myXML, "w+"); fwrite($fHandle, $content); fclose($fHandle); ?> Kurā parsējamā skripta daļā būtu jāievieto šis?.. tobiš, kad noteikt failu, kad atvērt, rakstīt.. un kad aizvērt failu? (..dēļ tā "foreach" ir neskaidrības..) ..paldies! Link to comment Share on other sites More sharing options...
bubu Posted June 20, 2007 Report Share Posted June 20, 2007 Atbildi uz šiem jautājumiem: Ko dara echo $output? (kādu datu tipu, kur izdrukā?) Kā atvērt failu? Kā failā ierakstīt stringu? Kā aizvērt failu? Link to comment Share on other sites More sharing options...
SadDemon Posted June 20, 2007 Author Report Share Posted June 20, 2007 Paldies "bubu"! Gan beigās vēl vajadzētu "</Noliktava>" tagu, tākā rakstīšana notiek iekš "foreach".. tur to likt nevar. Kā lai dabū dokumenta beigas, lai pievienotu aizveramo tagu? *.php saturs: <?php // .... $myXML = "../xml/temporary.xml"; $ending = "</Noliktava>"; $data = file_get_contents($myXML); $data = substr($data, 0, strpos($data, $ending)-1); foreach ($content as $output) { echo $output; $newData = "$output "; $data.=$newData; $fHandle = fopen($myXML, "w+"); fwrite($fHandle, $data); } fclose($fHandle); ?> Link to comment Share on other sites More sharing options...
andrisp Posted June 20, 2007 Report Share Posted June 20, 2007 Neraksti outputu uzreiz faila. Iekš tā foreac kabini to klāt visu laiku vienam mainīgajam, un pēc tam kad foreach izpildījies, ieraksti to visu stringu iekš faila. Tad varēsi arī vēl kaut ko beigās piekabināt. Link to comment Share on other sites More sharing options...
SadDemon Posted June 20, 2007 Author Report Share Posted June 20, 2007 Vēlreiz paldies.. gan bubu, gan andrisp! ..viss kārtībā.. Link to comment Share on other sites More sharing options...
bubu Posted June 20, 2007 Report Share Posted June 20, 2007 Tieši otrādi - raksti uzreiz failā, nevis kabini stringā. Pie lielākiem XML daudz atmiņas citādi vajadzēs (pārsniegsi vēl maģisko 8MB robežu). Paskaties uz savu kodu saskati cik reizes tu atver failu un cik reizes aizver - kautkā skaits nesakrīt, ne? Link to comment Share on other sites More sharing options...
SadDemon Posted June 21, 2007 Author Report Share Posted June 21, 2007 Nu mans skripts tagad ir šāds: <?php $doc = new DOMDocument; $doc -> load('../xml/depot.xml'); $content = array(); $products = $doc -> getElementsByTagName('product'); foreach ($products as $product) { $id = $product -> getAttribute('id'); $amount = $product -> getAttribute('amount'); $name = $product -> getAttribute('name'); $color = $product -> getAttribute('color'); $article = $product -> getAttribute('article'); $category = $product -> getAttribute('category'); $status = $product -> getAttribute('status'); $row = " <"."product id=\"".$id."\" amount=\"".$amount."\" name=\"".$name."\" color=\"".$color."\" article=\"".$article."\" category=\"".$category."\" status=\"".$status."\" />"; $content[$id] = $row; } ksort($content); $myXML = "../xml/temporary.xml"; $ending = "</Noliktava>"; $data = file_get_contents($myXML); $data = substr($data, 0, strpos($data, $ending)-1); foreach ($content as $output) { echo $output; $newData = "$output "; $data.=$newData; } $final_data = $data. $ending; $fHandle = fopen($myXML, "w+"); fwrite($fHandle, $final_data); fclose($fHandle); ?> ..apjomi itkā ļoti lieli nebūs, bet varētu tuvāk paskaidrot - kas ir tā "maģiskā 8 Mb robeža"? Link to comment Share on other sites More sharing options...
andrisp Posted June 21, 2007 Report Share Posted June 21, 2007 Noklusēti PHP drīkst izmantot tikai 8MB operatīvās atmiņas. Ja skripts sāk tērēt vairāk, tad tas nomirst ar kļūdas paziņojumu. Šo var mainīt iekš php.ini, saucas memory_limit. Link to comment Share on other sites More sharing options...
Recommended Posts