Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

XML tag suivant

7 réponses
Avatar
Une Bévue
J'ai un XML :
<root>
<destination ... />
<data><!--[CDATA ... --></data>
[meme chose plusieurs fois : destination, data]
<\root>

Disons que j'ai un node destination, comment j'ai le nœud data qui suit ?

Exemple :
Var destinations=doc.getElementsByTagName('destination');
var destination=destinations[0];

C'est :
var data=destination.nextSibling();
???

--
Une Bévue

7 réponses

Avatar
Matt...
Le Sat, 05 Nov 2011 18:51:17 +0100, Une Bévue nvalid>
a écrit:

J'ai un XML :
<root>
<destination ... />
<data><!--[CDATA ... --></data>
[meme chose plusieurs fois : destination, data]
<root>

Disons que j'ai un node destination, comment j'ai le nœud data qu i suit ?

Exemple :
Var destinations=doc.getElementsByTagName('destination');
var destinationstinations[0];

C'est :
var datastination.nextSibling();
???




Bonsoir,

var nData = destinations.getElementsByTagName('data');
var data = nData.item(0);

Matt...

--
Utilisant le client e-mail révolutionnaire d'Opera :
http://www.opera.com/mail/
Avatar
Une Bévue
On 05/11/2011 23:05, Matt... wrote:
var nData = destinations.getElementsByTagName('data');
var data = nData.item(0);



ah oui, mais c'est bien sûr !
Oeuf corse ;-)
Avatar
Une Bévue
On 05/11/2011 23:05, Matt... wrote:
var nData = destinations.getElementsByTagName('data');
var data = nData.item(0);



ben non, ce n'est pas ça car le noeud data n'est pas un enfant du noeud
destination :
<root>
<destination ... />
<data><![CDATA[ ... ]]></data>
...
<destination ... />
<data><![CDATA[ ... ]]></data>
</root>

par contre, il y a tjs un noeud data après un noeud destination, donc je
peux faire :

var doc = xhr.responseXML;
var root = doc.getElementsByTagName('root').item(0);
var destinations = doc.getElementsByTagName('destination');
var dest_length = destinations.length;
var datas = doc.getElementsByTagName('data');
var datas_length = datas.length;
if(dest_length === datas_length) { // meme nb de noeuds ?
for(var i=0; i < dest_length; i++) {
var destination = destinations[i];
var data = datas[i];
// suite du traitement
}
}


je précise qu'avec nextSibling(), ça ne marche pas car si je fais :
var data = destination.nextSibling();

Chrome me dit :
Uncaught TypeError: Property 'nextSibling' of object #<Element> is not a
function

ce que je ne comprends pas, ça aurait du marcher à l'exception du fait
qu'il peut y avoir un noeud texte entre <destination /> et <data /> :
<http://v3.thewatchmakerproject.com/journal/329/finding-html-elements-using-javascript-nextsibling-and-previoussibling&gt;
Avatar
Une Bévue
On 06/11/2011 15:42, Une Bévue wrote:


je précise qu'avec nextSibling(), ça ne marche pas car si je fais :
var data = destination.nextSibling();

Chrome me dit :
Uncaught TypeError: Property 'nextSibling' of object #<Element> is not a
function



pigé, ce n'est pas #nextSibling() mais #nextSibling sans les ()...

et là, ça roule si on teste bien le type de noeud...
Avatar
SAM
Le 05/11/11 18:51, Une Bévue a écrit :
J'ai un XML :
<root>
<destination ... />
<data><!--[CDATA ... --></data>
[meme chose plusieurs fois : destination, data]
<root>

Disons que j'ai un node destination, comment j'ai le nœud data qui suit ?

Exemple :
Var destinations=doc.getElementsByTagName('destination');



var destinations=doc.getElementsByTagName('destination');

var destinationÞstinations[0];



if(destinations) var destinationÞstinations[0];

C'est :
var dataÞstination.nextSibling();
???



if(destination) var dataÞstination.nextSibling();

Oui, ça me semble pas mal, non ?

sibling = enfant de mêmes parents (Google)

<http://fr.selfhtml.org/javascript/objets/node.htm&gt;
<http://fr.selfhtml.org/javascript/objets/node.htm#next_sibling&gt;

« La propriété nextSilbing traite respectivement le nœud qui suit dans
l'arborescence sans tenir compte cependant des nœuds enfant qui
pourraient être contenus dans un nœud. »


nextSibling renvoie 'null' si pas de "frère suivant" trouvé.


--
Stéphane Moriaux avec/with iMac-intel
Avatar
SAM
Le 06/11/11 15:58, Une Bévue a écrit :

pigé, ce n'est pas #nextSibling() mais #nextSibling sans les ()...



Ha ! Ben ! voui !

esssecuse !
j'avais relevé les autres erreurs mais pas celle-là ... ! :-(


--
Stéphane Moriaux avec/with iMac-intel
Avatar
Une Bévue
On 06/11/2011 16:33, SAM wrote:
Le 05/11/11 18:51, Une Bévue a écrit :
J'ai un XML :
<root>
<destination ... />
<data><!--[CDATA ... --></data>
[meme chose plusieurs fois : destination, data]
<root>

Disons que j'ai un node destination, comment j'ai le nœud data qui suit ?

Exemple :
Var destinations=doc.getElementsByTagName('destination');



var destinations=doc.getElementsByTagName('destination');



euh, je ne vois pas la différence...
ah le grand V de var, c'est la faute au correcteur ortaugraffic
d'iPhone, super chiant !!!
créé par de fiéfés imbéciles !!!


var destinationÞstinations[0];



if(destinations) var destinationÞstinations[0];

C'est :
var dataÞstination.nextSibling();
???



if(destination) var dataÞstination.nextSibling();

Oui, ça me semble pas mal, non ?

sibling = enfant de mêmes parents (Google)

<http://fr.selfhtml.org/javascript/objets/node.htm&gt;
<http://fr.selfhtml.org/javascript/objets/node.htm#next_sibling&gt;



ok merci pour les refs, j'ai résolu in between )))

« La propriété nextSilbing traite respectivement le nœud qui suit dans
l'arborescence sans tenir compte cependant des nœuds enfant qui
pourraient être contenus dans un nœud. »


nextSibling renvoie 'null' si pas de "frère suivant" trouvé.