标签:
<?php $dbconn = mysql_connect("localhost","root","root"); $db = mysql_select_db("xbrl",$dbconn); $xml = simplexml_load_file("test.xml"); $name = "" ; $price = 0.00 ; foreach ($xml->children() as $child){ $i = 0 ; foreach ($child->children() as $kid){ if($i==0){ $name = $kid ; $i++ ; }else{ $price = $kid ; $i--; } } $sql = "insert into t_car(name,price) values(‘$name‘,$price)" ; mysql_query($sql,$dbconn); } ?>
xml文件内容
<?xml version="1.0" encoding="UTF-8"?> <OBJECT> <CAR> <NAME>BMW</NAME> <PRICE>10000</PRICE> </CAR> <CAR> <NAME>BENZ</NAME> <PRICE>10000</PRICE> </CAR> <CAR> <NAME>TOYOTA</NAME> <PRICE>10000</PRICE> </CAR> <CAR> <NAME>HONDA</NAME> <PRICE>10000</PRICE> </CAR> </OBJECT>
标签:
原文地址:http://www.cnblogs.com/walter371/p/4475525.html