From:             adminsun at 126 dot com
Operating system: WindowsXP
PHP version:      5.0.3
PHP Bug Type:     XML related
Bug description:  XML in PHP5

Description:
------------
This Code in PHP 4 running is ok, But in PHP5 Display "XML error: Invalid
character at line 2", Why??

Reproduce code:
---------------
function makeTree($XML_FILE = ""){
                if(get_magic_quotes_runtime()){
                        set_magic_quotes_runtime (0);
                        $mq = 1;
                }
    $this->parser = xml_parser_create();
    xml_set_object($this->parser, &$this);
    xml_set_element_handler($this->parser, "startElement", "endElement");
    xml_set_character_data_handler ( $this->parser, "dataElement");
    if($XML_FILE){
      if (!($fp = fopen($XML_FILE, "r"))) {
        die("Could not open XML file");
      }
    }
    else{
      if (!($fp = fopen($this->file, "r"))) {
        die("Could not open XML file");
      }
    }

    while ($data = fread($fp, 4096)) {
        $ffile=xml_parse($this->parser, $data, feof($fp));
      if (!$ffile) {
        die(sprintf("XML error: %s at line %d",
                    xml_error_string(xml_get_error_code($this->parser)),
                    xml_get_current_line_number($this->parser)));
      }
    }
    xml_parser_free($this->parser);
                if($mq){
                        set_magic_quotes_runtime (1);
                }
    return $this->displayTree();

  } // end makeTree()


//----------------------------------------------------------------------------------------
  function makeTreeText($XML_TEXT = ""){
                if(get_magic_quotes_runtime()){
                        set_magic_quotes_runtime (0);
                        $mq = 1;
                }
    $this->parser = xml_parser_create();
    xml_set_object($this->parser, &$this);
    xml_set_element_handler($this->parser, "startElement", "endElement");
    xml_set_character_data_handler ( $this->parser, "dataElement");

    if($XML_TEXT=="")
    {
        die("XML TEXT is empty!");
    }

    $POS=0;
    $LEN=strlen($XML_TEXT);
    while ($data = substr($XML_TEXT,$POS, 4096)) {
      $data=str_replace("\0","/0",$data);
      $data=str_replace("&","&",$data);
      $cdata=xml_parse($this->parser, $data, 0);
      if (!$cdata) {
        die(sprintf("XML error: %s at line %d",
                    xml_error_string(xml_get_error_code($this->parser)),
                    xml_get_current_line_number($this->parser)));
      }

      $POS+=4096;
      if($POS>=$LEN)
         break;
    }
    xml_parser_free($this->parser);
                if($mq){
                        set_magic_quotes_runtime (1);
                }
    return $this->displayTree();

  } // end makeTree()



-- 
Edit bug report at http://bugs.php.net/?id=31291&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31291&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31291&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31291&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31291&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31291&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31291&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31291&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31291&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31291&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31291&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=31291&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=31291&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31291&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31291&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31291&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31291&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31291&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31291&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=31291&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31291&r=mysqlcfg

Reply via email to