SadDemon Posted June 19, 2007 Report Share Posted June 19, 2007 (edited) Ir nepieciešams veikt meklējumu parsējamā failā, piemēram.. nosakam, ka meklējamais ir "id" attribūts ar lielumu "5".. un atrodot attiecīgo rindiņu, tā tiek aizvietota ar citu, ieprikš noteiktu rindiņu.. (nezinu, kurā koda daļā tas būtu jāveic.. un kā) Lūdzu palīdzēt.. tagadējais *.php fails outputā izmet k-ko līdzīgu *.xml faila struktūrai.. *.php faila saturs ir: <?php $file = "depot.xml"; function startElement($parser, $name, $attributes) { echo "<font color=" . "\"" . "#000099" . "\"" . ">" . "<" . "$name" . " " . "</font>"; if (sizeof($attributes)) { while (list($object, $value) = each($attributes)) { echo "<font color=" . "\"" . "#000099" . "\"" . ">" . "$object" . "=" . "</font>" . "<font color=" . "\"" . "#006600" . "\"" . ">" . "\"" . "$value" . "\"" . "</font>" . " "; } } echo "<font color=" . "\"" . "#000099" . "\"" . ">" . ">" . "</font>"; } function endElement($parser, $name) { echo "<font color=" . "\"" . "#000099" . "\"" . ">" . "</" . "$name" . ">" . "</font>"; } function characterData($parser, $data) { echo "$data"; } function new_xml_parser($file) { global $parser_file; $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); if (!($fp = @fopen($file, "r"))) { return false; } if (!is_array($parser_file)) { settype($parser_file, "array"); } $parser_file[$xml_parser] = $file; return array($xml_parser, $fp); } if (!(list($xml_parser, $fp) = new_xml_parser($file))) { die("Could not open xml input"); } echo "<pre>"; while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("Xml error: %s at line %d" . "\n", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); ?> output: <Noliktava produkcijai="----" > <product id="1" amount="51" name="basketbola bumba" color="oranža" article="-" category="citi" status="ir" ></product> <product id="2" amount="7" name="vizītkaršu etvija" color="metāls" article="50042" category="birojam" status="ir" ></product> <product id="3" amount="25" name="vizītkaršu etvija" color="metāls" article="ap802301" category="birojam" status="ir" ></product> <product id="4" amount="27" name="vizītkaršu etvija" color="metāls" article="1602270" category="birojam" status="ir" ></product> </Noliktava> Edited June 19, 2007 by SadDemon Link to comment Share on other sites More sharing options...
bubu Posted June 19, 2007 Report Share Posted June 19, 2007 Kas ir šis $attributes? function startElement($parser, $name, $attributes) { echo "<font color=" . "\"" . "#000099" . "\"" . ">" . "<" . "$name" . " " . "</font>"; ... Link to comment Share on other sites More sharing options...
SadDemon Posted June 19, 2007 Author Report Share Posted June 19, 2007 (edited) Njā.. būs kāda kļūda tā šķiet, ja padomā - pats īsti nezinu, jo izrāvu kādu gabalu no viena piemēra.. un $attributes ir "undefined" Edited June 19, 2007 by SadDemon Link to comment Share on other sites More sharing options...
SadDemon Posted June 19, 2007 Author Report Share Posted June 19, 2007 ..nu principā noskaidroju, ka (..galējā variantā tiks hostēts uz serveris.lv) ..ir iespēja pieprasīt Dom funkcijas atbalstu.. tākā atgriežos pie Dom metodes izpētes un apgūšanas.. Topiks uz dzēšanu.. (atvainojos par piesārņošanu) Link to comment Share on other sites More sharing options...
Recommended Posts