Page 1 of 1

Getting error of XML Parser

Posted: Mon Jun 12, 2006 5:12 am
by ghfazil
twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I am getting error when I am trying to run php file for reading data from xml file.

Warning: xml_parser_set_option(): supplied argument is not a valid XML Parser resource in C:\LSST\Apache2\Apache2\htdocs\Web\A&RDVD\A&RAdmin\show.php on line 45

Warning: xml_set_element_handler(): 2 is not a valid XML Parser resource in C:\LSST\Apache2\Apache2\htdocs\Web\A&RDVD\A&RAdmin\show.php on line 46

Warning: xml_set_character_data_handler(): 2 is not a valid XML Parser resource in C:\LSST\Apache2\Apache2\htdocs\Web\A&RDVD\A&RAdmin\show.php on line 47

I am new to xml parsing. I write the code form the example tutorial on the net. The code is

Code: Select all

<?php
	$filename = "dvdsxml.xml";
	$xmlparser = xml_parser_create();
	
	function start_tag($parser, $name, $attribs)
	{
		echo "Current tag : ".$name."<br />"; 
   		if (is_array($attribs))
		{ 
      		echo "Attributes : <br />"; 
      		while(list($key,$val) = each($attribs))
				echo "Attribute ".$key." has value ".$val."<br />"; 
       	} 
	}
	
	function end_tag($parser, $name)
	{
		echo "Reached ending tag ".$name."<br /><br />"; 
	}
	
	function tag_contents($parser, $data)
	{ 
   		echo "Contents : ".$data."<br />"; 
	}
	
	if (!$xmlparser ) 
 		die ("Cannot create parser"); 
	else
	{
		if (!($fp = fopen($filename, "r")))
			die("cannot open ".$filename);
		else
		{
			while ($data = fread($fp, 4096))
			{ 
				if (!xml_parse($xmlparser, $data, feof($fp)))
				{ 
					$reason = xml_error_string(xml_get_error_code($xmlparser)); 
					$reason .= xml_get_current_line_number($xmlparser); 
					die($reason); 
				} 
			}
			
			xml_parser_free($xmlparser);
			xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1);
			xml_set_element_handler($xmlparser, "start_tag", "end_tag");
			xml_set_character_data_handler($xmlparser, "tag_contents");
		}
	}

?>
I want to read the data from XML file and allow user to select the dvds he want to save in Mysql database. I am unable to get a way around it.

Any idea how can I achieve this??


twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Jun 12, 2006 9:56 am
by ghfazil
Thank you next time i will take care in posting code