1: <title>xml 转换为 sql</title>
2: <meta http-equiv='content-type' content='text/html; charset=utf-8' />
3: <style type="text/css">
4: .tip_info {margin-bottom:10px;}
5: .tip_info span {color:#f00;}
6: </style>
7: <?php
8: $xml = "D:/res/dressConfig.xml";
9: $doc = new DOMDocument();
10: $doc->load($xml);
11: $xpath = new DOMXPath($doc);
12: $query = "//i";
13: $entries = $xpath->query($query);
14: $len = $entries->length;
15:
16: echo "<div class='tip_info'>总共找到:<span>".$len."</span>个节点</div>";
17:
18: $arr = array();
19:
20: $idx = 0;
21: while ($idx < $len) {
22: $nodeItem = $entries->item($idx);
23: $id = $nodeItem->getAttribute("i");
24: $name = $nodeItem->getAttribute("n");
25: $inf = $nodeItem->getAttribute("inf");
26:
27: // echo "<div>".$id.'--'.$name.'--'.$inf."</div>";
28: $idx++;
29:
30: array_push($arr, "update dress_item t SET t.s_name='".$name."',t.s_intro='".$inf."' WHERE t.n_doid=".$id.";");
31: }
32:
33: $dir = "d:/sql/";
34:
35: if (!is_dir($dir)) {
36: mkdir($dir);
37: }
38:
39: file_put_contents("d:/sql/dress_item.sql", implode("\n\r", $arr));
40: echo "生成完毕!";
41: ?>