Re: [PHP] [xml] character data
Tom Rogers wrote: 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? [ snipped ] 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; Or you can strip all the whitespace from the xml document and send that in. -- Burhan Khalid phplist[at]meidomus[dot]com http://www.meidomus.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [xml] character data
What Tom has to say + you should note that character data may be called more than once for each call to startElement. Tom Rogers wrote: 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, DAxml_error_string(xml_get_error_code($xml_parser)), DAxml_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; -- Raditha Dissanayake. http://www.radinks.com/sftp/ | http://www.raditha/megaupload/ Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader Graphical User Inteface. Just 150 KB | with progress bar. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] [xml] character data
I do not understand why this line does not work : $info[$element] = $content; but yet this works: echo $content; why? what is the trick? -- $xml_comment_file = basename($svg_file, '.svg.xml') .'.info.xml'; if (file_exists($xml_comment_file)) { $file = $xml_comment_file; $info = array(); $element = null; function startElement($parser, $name, $attrs) { global $element; $element = $name; } function endElement($parser, $name) { print ; } function characterData($parser, $content) { global $info; global $element; $info[$element] = $content; //$info[$element] = sprintf(%s, $content); } $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, FALSE); xml_set_element_handler($xml_parser, startElement, endElement); xml_set_character_data_handler($xml_parser, characterData); if (!($fp = fopen($file, 'r'))) die(could not open XML input\n); while ($data = fread($fp, 4096)) if (!xml_parse($xml_parser, $data, feof($fp))) die(sprintf(XML error: %s at line %d, xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); xml_parser_free($xml_parser); print_r($info); } /* # the output is without $content : Array ( [info] = [file] = [orig-file] = [orig-author] = [bitmap-src] = [orig-date] = [svg-date] = ) */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [xml] character data
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, DAxml_error_string(xml_get_error_code($xml_parser)), DAxml_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