1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <?php
$string = "<lg><l>
<w lemma=\"je\" pos=\"PRO\">J</w>
<w lemma=\"avoir\" pos=\"ADV\">eu</w>
</l>
</lg>";
$xml = simplexml_load_string($string);
// table de correspondance
$data['pos'] = 'nomChampsPOSDansBDD';
$data['lemma'] = 'nomChampsLemmeDansBDD';
$result = $xml->xpath("//lg/l/w");
while(list( , $node) = each($result)) {
$sqlFields = array();
foreach($node->attributes() as $attrName => $attrValue) {
$sqlFields[] = $data[$attrName].' = "'.$attrValue.'"';
}
$sql[] = 'INSERT into table SET '.implode(', ', $sqlFields);
}
echo '<pre>';
var_dump($sql);
echo '</pre>';
?> |
Partager