Bonjour,
je souhaiterai parser du xml grace a jquery.
une partie de mon fichier ressemble a cela :
je souhaiterai avoir ce résultat :
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
23
24 <s> <phr type="DP" function="subj"> <w type="det" lemma="le">Le</w> <w type="adj" lemma="joli">joli</w> <w type="nom" lemma="chat">chat</w> <phr type="" function="D-obj"> <w type="pro" lemma="que">que</w> </phr> <phr type="" function="subj"> <w type="nom" lemma="je">j'</w> </phr> <phr type="" function="predicate"> <w type="aux" lemma="avoir">ai</w> <phr type="" function="CC"> <w type="adv" lemma="gentiment">gentiment</w> </phr> <w type="partpass" lemma="adopter">adopté</w> </phr> </phr> </s>
jai commencé un bout de code qui ressemble à sa :
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 <span class="subj"> <span class="det" title="Déterminant défini - Masculin Singulier">le</span> <span class="adj" title="Adjectif - Masculin Singulier">joli</span> <span class="nom" title="Nom Commun - Masculin Singulier">chat</span> <span class="D-obj"> <span class="pro" title="Pronom Relatif - Singulier Masculin">que</span> </span> <span class="subj"> <span class="nom" title="Pronom Personnel - 1ère Personne Singulier">j'</span> </span> <span class="predicate"> <span class="aux" title="Verbe Auxiliaire - Indicatif 1ère Personne Singulier">ai</span> <span class="CC"> <span class="adv" title="Adverbe">gentiment</span> </span> <span class="partpass" title="Verbe - Participe Passé">adopté</span> </span> </span>
mon probleme est que je narrive pas a representer la hierarchie. pour les phr pas de soucis mais quand un element phr est contenu dans un phr alors la je narrive pas a garder la hierarchie pere=>fils
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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 $(document).ready(function(){ $.ajax({ type: "GET", url: "../xml-adhoc/test.xml", dataType: "xml", success: function(xml) { $(xml).find('s').each(function(){ //recuperation de l'identifiant de la Phrase var id = $(this).attr('id'); //Recuperation de l'id de chaque phrase $('<h3><i>Phrase : '+id+'</i></h3>').appendTo('#phrase'); //recup de chaque ÈlÈments W de la phrase $(this).find('phr').each(function(){ //RECUP FS var FunctSynt = $(this).attr('function'); var WORD = $(this).find('w').text(); var FS = $(this).find('w').text(); $('<span class="'+FunctSynt+'"> '+FunctSynt+' '+WORD+'</span> ').appendTo('#phrase'); $('<hr>').appendTo('#phrase'); }); }); } }); });
merci
Partager