Salut,

voici la structure de mon fichier XML

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<mysql>
  <database name="personnes">
    <table>
        <fiche>
          <var name="id">..</var>
          <var name="nom">...</var>
          <var name="prenom">...</var>
          <var name="statut">...</var>
          <var name="formation">...</var>
          <var name="pageWebPerso" generation="auto"></var>
          <var name="photo"></var>
          <var name="distinctions" generation="none"></var>
          <var name="implicationprojet"><projet>projet1</projet><projet>projet2</projet></var>
          <var name="tel"></var>
          <var name="local"></var>
          <var name="courriel"></var>
          <var name="implicationlabo">5059<laboratoire>..</laboratoire></var>
        </fiche>
    </table>
  </database>
</mysql>
mon problémes c'est comment modifier les données dans les balises <projet></projet> sachant que le nombre de ces balises dans le champs <implicationprojet> peut augmenter ou diminuer! et meme chose pour <implicationlabo> , c'est le meme concept.

et aussi comment modifier le champs generation !!!

voici le code que j'ai, je vais l'expliquer un peu

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
function getFicheById($dom, $id)
{
    $xpath = new DOMXPath($dom);
    $res = $xpath->query(sprintf('//fiche[var[@name = "id"]/text() = "%d"]', $id));
    if ($res->length == 1) {
        return $res->item(0);
    } else {
        return FALSE;
    }
}
ca retourne la fiche courante , à partir du id, c'est à dire la fiche a modifier

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
function ficheToNodeArray($fiche)
{
    $vars = array();
    foreach ($fiche->firstChild->childNodes as $v) {
        if ($v->tagName == 'var' && $v->hasAttribute('name')) {
            $vars[utf8_decode($v->getAttribute('name'))] = $v;
        }
    }
    return $vars;
}
permet la modification des valeurs avec cette facon :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
$noeuds = ficheToNodeArray($fiche, $_POST['id']);
	$noeuds['nom']->nodeValue = utf8_encode($_POST['nom']);
	$noeuds['prenom']->nodeValue = utf8_encode($_POST['prenom']);
	$noeuds['statut']->nodeValue = utf8_encode($_POST['statut']);
	$noeuds['formation']->nodeValue = utf8_encode($_POST['formation']);
	$noeuds['pageWebPerso']->nodeValue = utf8_encode($_POST['pageWebPerso']);
	$noeuds['tel']->nodeValue = utf8_encode($_POST['tel']);
	$noeuds['photo']->nodeValue = utf8_encode($_POST['photo']);
	$noeuds['distinctions']->nodeValue = utf8_encode($_POST['distinctions']);


finalement, j'ai les valeurs des projets, et des laboratoires dans des array

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$proj=array();
	$i=0;
	if(isset($_POST['implicationprojet']))
	{
		foreach ($_POST['implicationprojet'] as $v) {
		   if ($v){
			 $proj[$i]=$v;
			 $i++;
		   }
		 }
	}
	$labs=array();
	$i=0;
	if(isset($_POST['implicationlabo']))
	{
		foreach ($_POST['implicationlabo'] as $v) {
		   if ($v){
			 $proj[$i]=$v;
			 $i++;
		   }
		 }
	}
toutes les données proviennent d'un formulaire ...


Merci.



...