Connecting Tech Pros Worldwide Help | Site Map

XML parser error...

Newbie
 
Join Date: Nov 2006
Posts: 1
#1: Nov 22 '06
Hi all
I am novice in XML. I have just started to creating PHP parser for XML files. I am using SAX.
the file is : -
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <basefont face="Arial">
  4. </head>
  5. <body>
  6. <?php
  7. // cdata handler
  8. function characterDataHandler($parser, $data)
  9. {
  10.       echo $data . "<p>";
  11. }
  12.  
  13. // PI handler
  14. function PIHandler($parser, $target, $data)
  15. {
  16.       // if php code, execute it
  17.       if (strtolower($target) == "php")
  18.       {
  19.            eval($data);
  20.       }
  21.       // otherwise just print it
  22.       else
  23.       {
  24.             echo "PI found: [$target] $data";
  25.       }
  26. }
  27.  
  28. // XML data
  29. $xml_data = <<<EOF
  30. <?xml version="1.0"?>
  31. <article>
  32.       <header>insert slug here</header>
  33.       <body>insert body here</body>
  34.       <footer><?php print "Copyright UNoHoo Inc," . date("Y", mktime()); ?></footer>  
  35. </article>
  36. EOF;
  37.  
  38. // initialize parser
  39. $xml_parser = xml_parser_create();
  40. // set cdata handler
  41. xml_set_character_data_handler($xml_parser, "characterDataHandler");
  42. // set PI handler
  43. xml_set_processing_instruction_handler($xml_parser, "PIHandler");
  44. if (!xml_parse($xml_parser, $xml_data))
  45. {
  46.       die("XML parser error: " .
  47. xml_error_string(xml_get_error_code($xml_parser)));
  48. }
  49.  
  50. // all done, clean up!
  51. xml_parser_free($xml_parser);
  52. ?>
  53. </body>
  54. </html>
Next time read the Posting Guidelines at the top of this forum before you post anything! Especially the part about enclosing shown code within code, php or html tags! - Ronald

it give this output " XML parser error: Reserved XML Name"

I am unable to understand why its come.

Please help me out.
onewaylife
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Nov 22 '06

re: XML parser error...


I think this SAX question belongs in the XML forum. I will transfer it.

Ronald :cool:
Reply