php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31291 XML in PHP5
Submitted: 2004-12-25 09:42 UTC Modified: 2004-12-25 21:20 UTC
From: adminsun at 126 dot com Assigned:
Status: Not a bug Package: XML related
PHP Version: 5.0.3 OS: WindowsXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: adminsun at 126 dot com
New email:
PHP Version: OS:

 

 [2004-12-25 09:42 UTC] adminsun at 126 dot com
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()



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-25 21:20 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Jan 25 11:01:23 2021 UTC