I am having some xml file and i want to parse the XML data and store it in corresponding fields in the mysql table can any one please sort my problem.. Thank u in advance
hi, in w3schools you can find useful basic examples to do it. here is the link: http://www.w3schools.com/php/default.asp
I try all the think but i cant get the data to store it to the database. $xmlDoc->load("xm URl"); $books = $xmlDoc->documentElement; $i=0; foreach ($books->childNodes As $child_node) { $i++; $book1 = $book->nodeName; // echo $book1; if($child_node->hasChildNodes()) { $book_name = $child_node->nodeName; echo $book_name; if($book_name == "AirportName") { $data_array[] = $child_node->nodeValue; if($book_name == "Location") { $data_array[] = $child_node->nodeValue; if($book_name == "AirportOverview") { $data_array[] = $child_node->nodeValue; if($book_name == "ByBus") { $data_array[] = $child_node->nodeValue; if($book_name == "ByTaxi") { $data_array[] = $child_node->nodeValue; if($book_name == "ByTrain") { $data_array[] = $child_node->nodeValue; if($book_name == "PhoneNum") { $data_array[] = $child_node->nodeValue; if($book_name == "Website") { $data_array[] = $child_node->nodeValue; } } } } } } } } } $boo = mysql_escape_string($data_array[0]); echo $boo . "</br>"; echo $data_array[1] . "</br>"; echo $data_array[2] . "</br>"; echo $data_array[3] . "</br>"; echo $data_array[4] . "</br>"; echo $data_array[5] . "</br>"; echo $data_array[6] . "</br>"; echo $data_array[7] . "</br>"; $sql = "INSERT INTO adetails VALUES('$data_array[0]','$data_array[1]','$data_array[2]','$data_array[3]','$data_array[4]','$data_array[5]','$data_array[6]','$data_array[7]')"; $q = mysql_query($sql); unset($data_array); // } } // $sql = "INSERT INTO adetails (name,location,airportoverview,bybus,bycar,bytrain,phno,website) // VALUES('$data_array[0]','$data_array[1]','$data_array[2]','$data_array[3]','$book','$data_array[5]','$data_array[6]','$data_array[7]')"; // $q = mysql_query($sql); mysql_close($connect); ?>
or use the load string: // xml testing // $xml_file = "5300538.xml"; // load the nzb // $xml = simplexml_load_file("$xml_file"); // test // foreach ($xml as $details) { ############################################### # Put the details into variables ############################################### $n_date = $details['date']; $n_poster = $details['poster']; $n_subject = $details['subject']; print("<b>Date</b> - ") . $n_date; print("<br />"); print("<b>Posted By</b> - ") . $n_poster; print("<br />"); print("<b>Subject</b> - ") . $n_subject; print("<br />"); // another foreach for the group // foreach($details->groups->group as $group) { print("<b>Group</b> - ") . $group; } } PHP: this can be modified for your needs though. Graham