note 43203 added to function.xml-parse-into-struct

From: Date: Mon, 14 Jun 2004 02:12:12 +0000
Subject: note 43203 added to function.xml-parse-into-struct
Groups: php.notes 
Request: Send a blank email to php-notes+get-71024@lists.php.net to get a copy of this message
(The previous post I wrote was incorrect. I fix that herein) I used the algorithm from stephane for writing back to a file, but ran into the following problem. My original XML looks like <ENTRY id="1"> ... </ENTRY><ENTRY id="2"> ... </ENTRY> This got saved back as <1> ... </1><2> ... </2>, which expat doesn't like. So I propose the following modification: function writeXmlToFile($data, $f, $niv = 0) { foreach($data as $name => $elem) { if (preg_match("/\A[0-9]/",$name)) { $open = "ENTRY id=\"$name\""; $name = "ENTRY"; } else { $open = $name; } if(is_array($elem)) { fwrite($f, str_repeat(" ", $niv)."<".$open.">"."\n"); writeXmlToFile($elem, $f, $niv + 1); fwrite($f, str_repeat(" ", $niv)."</".$name.">"."\n"); } else { fwrite($f, str_repeat(" ", $niv)."<".$open.">".$elem."</".$name.">"."\n"); } } } ---- Manual Page -- http://www.php.net/manual/en/function.xml-parse-into-struct.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43203 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43203&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43203&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#71024) next »