Dear all i am having a mysql database which is fed with a php form. i want to add an additional featute to the form: enter the data in mysql database using an xml file. The XML file may contain 1-10,000 enteries and each entry should form a unique entry in the mysql database. Please help me how can i 1) enter the xml data directly into the mysql db 2) Enter data from XML file using a php form. Any of the methods to enter the data are welcome. I am attaching a sample XML file which contains a number of enteries. Each entry starts with <PubmedArticle> tag and ends with </PubmedArticle> tag. Thanks in advance.
the data must be parsed into an array 1 by 1 and entered threw a sequence into the database. Are you wanting the code in which will do this? or just how its done?
yeah! thats going to be a great favour. Plz let me know the code to do it or a sample script. Thanks in advance.
<?php $insideitem = false; $tag = ""; $title = ""; $description = ""; $link = ""; function startElement($parser, $name, $attrs) { global $insideitem, $tag, $title, $description, $link; if ($insideitem) { $tag = $name; } elseif ($name == "ITEM") { $insideitem = true; } } function endElement($parser, $name) { global $insideitem, $tag, $title, $description, $link; if ($name == "ITEM") { printf("<dt><b><a href='%s'>%s</a></b></dt>", trim($link),htmlspecialchars(trim($title))); printf("<dd>%s</dd>",htmlspecialchars(trim($description))); $title = ""; $description = ""; $link = ""; $insideitem = false; } } function characterdata($parser, $data) { global $insideitem, $tag, $title, $description, $link; if ($insideitem) { switch ($tag) { case "TITLE": $title .= $data; break; case "DESCRIPTION": $description .= $data; break; case "LINK": $link .= $data; break; } } } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterdata"); $fp = fopen("*********","r") or die("Error reading RSS data."); while ($data = fread($fp, 4096)) xml_parse($xml_parser, $data, feof($fp)) or die(sprintf("xml error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); fclose($fp); xml_parser_free($xml_parser); ?> PHP:
Thanks a lot lowridertj. I will use it n will tell u the results soon. Hope I will be fine with your code. Cheers.