Re: [PHP-DB] XML coming out from MySQL
> I've never parsed XML with PHP, but it might help if you can show the > document that's breaking the parser, and also let us know if other > documents are working fine... > > -Lorenzo Hi, The document is like this: Some text Some text Some text Some text http://whatever.com/ Whomever 2001 Up to now, I solve the problem modifying the lines saying > while ($data = $file) { > if (!xml_parse($xml_parser, $data, 0)) { > die(sprintf("XML error: %s at line %d", > xml_error_string(xml_get_error_code($xml_parser)), > xml_get_current_line_number($xml_parser))); > } > } into > xml_parse($xml_parser, $data, 0); I'd noticed that I don't need to read the document line by line. Regards and thanks, Tomás +-- --+ Tomás García Ferrari Bigital http://bigital.com/ +-- --+ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] XML coming out from MySQL
I've never parsed XML with PHP, but it might help if you can show the document that's breaking the parser, and also let us know if other documents are working fine... -Lorenzo -Original Message- From: Tomas Garcia Ferrari Sent: Fri 11/9/2001 5:14 PM To: [EMAIL PROTECTED] Cc: Subject: [PHP-DB] XML coming out from MySQL Hello, I'm trying to parse an XML file stored on MySQL. I'm using this code: > global $CFG, $ME; > > $qid = db_query(" > SELECT texto > FROM articulos > WHERE id = $id > "); > > $r = db_fetch_object($qid); > $file = $r->texto; > > > $map_array = array( > "ARTICULO" => "", > "VOLANTA" => "h2", > "TITULO" => "h1", > "SUBTITULO" => "h3", > "BAJADA" => "h2", > "PARRAFO" => "p", > "AUTOR" => "h3", > "URL" => "h3", > "COPY" => "h3" > ); > > function startElement($parser, $name, $attrs) { > global $map_array; > if ($htmltag = $map_array[$name]) { > print "<$htmltag>"; > } > } > > function endElement($parser, $name) { > global $map_array; > if ($htmltag = $map_array[$name]) { > print ""; > } > } > > function characterData($parser, $data) { > print $data; > } > > $xml_parser = xml_parser_create(); > // use case-folding so we are sure to find the tag in $map_array > xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true); > xml_set_element_handler($xml_parser, "startElement", "endElement"); > xml_set_character_data_handler($xml_parser, "characterData"); > > while ($data = $file) { > if (!xml_parse($xml_parser, $data, 0)) { > 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); > ?> and having this at the end of the outuput: > XML error: junk after document element at line 25 What does it mean? How can I solve it / trace it? Regards, Tomás +-- --+ Tomás García Ferrari Bigital http://bigital.com/ +-- --+ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] XML coming out from MySQL
Hello, I'm trying to parse an XML file stored on MySQL. I'm using this code: > global $CFG, $ME; > > $qid = db_query(" > SELECT texto > FROM articulos > WHERE id = $id > "); > > $r = db_fetch_object($qid); > $file = $r->texto; > > > $map_array = array( > "ARTICULO" => "", > "VOLANTA" => "h2", > "TITULO" => "h1", > "SUBTITULO" => "h3", > "BAJADA" => "h2", > "PARRAFO" => "p", > "AUTOR" => "h3", > "URL" => "h3", > "COPY" => "h3" > ); > > function startElement($parser, $name, $attrs) { > global $map_array; > if ($htmltag = $map_array[$name]) { > print "<$htmltag>"; > } > } > > function endElement($parser, $name) { > global $map_array; > if ($htmltag = $map_array[$name]) { > print ""; > } > } > > function characterData($parser, $data) { > print $data; > } > > $xml_parser = xml_parser_create(); > // use case-folding so we are sure to find the tag in $map_array > xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true); > xml_set_element_handler($xml_parser, "startElement", "endElement"); > xml_set_character_data_handler($xml_parser, "characterData"); > > while ($data = $file) { > if (!xml_parse($xml_parser, $data, 0)) { > 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); > ?> and having this at the end of the outuput: > XML error: junk after document element at line 25 What does it mean? How can I solve it / trace it? Regards, Tomás +-- --+ Tomás García Ferrari Bigital http://bigital.com/ +-- --+ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]