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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| <?php
$fp = fopen("test.xml","r"); //ouverture en lecture
$xmlstr = "";
while (!feof($fp)) { //on parcourt toutes les lignes
$xmlstr .= fgets($fp, 4096); // lecture du contenu de la ligne
}
$xmlObject=new SimpleXMLElement($xmlstr);
$db=mysql_connect("localhost", "root") or die("connection impossible");
mysql_select_db("projet",$db) or die ("base non trouvé");
$result = $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="matricule"]/dsml:value');
$result1= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="entree"]/dsml:value');
$result2= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="civilite"]/dsml:value');
$result3= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="nomUsuel"]/dsml:value');
$result4= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="nomPatronymique"]/dsml:value');
$result5= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="nomMarital"]/dsml:value');
$result6= $xmlObject->xpath('//dsml:dsml/dsml:directory-entries/dsml:entry/dsml:attr[@name="prenom"]/dsml:value');
foreach ($result as $title) {
echo $title . "\n";
$st=(string)"$title";
foreach ($result1 as $title1) {
echo $title1 . "\n";
foreach ($result2 as $title2) {
echo $title2 . "\n";
foreach ($result3 as $title3) {
echo $title3 . "\n";
foreach ($result4 as $title4) {
echo $title4 . "\n";
foreach ($result5 as $title5) {
echo $title5 . "\n";
foreach ($result6 as $title6) {
echo $title6 . "\n";
$sql="INSERT INTO AGENT (matricule,entree,civilite,nomUsuel,nomPatronymique,nomMarital,prenom)
values('$st','$title1','$title2','$title3','$title4','$title5','$title6')";
mysql_query($sql) or die("erreur sur la requete sql");
}
}
}
}
}
}
}
}
mysql_close($db);
fclose($fp);
?> |
Partager