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:
> <?php
> 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 "</$htmltag>";
> }
> }
>
> 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]