Hi, Saturday, October 11, 2003, 6:26:01 AM, you wrote: DA> I do not understand why this line does not work : DA> $info[$element] = $content;
DA> but yet this works: echo $content; DA> why? what is the trick? DA> -- DA> $xml_comment_file = basename($svg_file, '.svg.xml') .'.info.xml'; DA> if (file_exists($xml_comment_file)) { DA> $file = $xml_comment_file; DA> $info = array(); DA> $element = null; DA> function startElement($parser, $name, $attrs) { DA> global $element; DA> $element = $name; DA> } DA> function endElement($parser, $name) { DA> print ""; DA> } DA> function characterData($parser, $content) { DA> global $info; DA> global $element; DA> $info[$element] = $content; DA> //$info[$element] = sprintf("%s", $content); DA> } DA> $xml_parser = xml_parser_create(); DA> xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, FALSE); DA> xml_set_element_handler($xml_parser, "startElement", "endElement"); DA> xml_set_character_data_handler($xml_parser, "characterData"); DA> if (!($fp = fopen($file, 'r'))) DA> die("could not open XML input\n"); DA> while ($data = fread($fp, 4096)) DA> if (!xml_parse($xml_parser, $data, feof($fp))) DA> die(sprintf("XML error: %s at line %d", DA> xml_error_string(xml_get_error_code($xml_parser)), DA> xml_get_current_line_number($xml_parser))); DA> xml_parser_free($xml_parser); DA> print_r($info); DA> } DA> /* DA> # the output is without $content : DA> Array DA> ( DA> [info] => DA> [file] => DA> [orig-file] => DA> [orig-author] => DA> [bitmap-src] => DA> [orig-date] => DA> [svg-date] => DA> ) DA> */ the function characterData can be called with whitespace which is probably overwriting your content try this $content = trim($content); if(!empty($content)) $info[$element] = $content; -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php