Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  65] [ 4]  / answers: 1 / hits: 15117  / 13 Years ago, thu, february 23, 2012, 12:00:00

I'm experimenting with this xml:



<theFeed>
<games>
<game id=103 period= clock=>
<team id=657 type=home logo=1/12 score=46/>
<team id=740 type=visitor seed=11 score=59/>
</game>
</games>
</theFeed>


and I'm trying to get the attribute score from the first child of the game node, but when I use this code(javascript):



var Hlogo = theXml.getElementsByTagName('game')[0].childNodes[0].getAttribute('score');


it crashes. I can get attributes from the parent just fine using getAttributes...
is there something I'm doing wrong?


More From » xml

 Answers
192
var game = theXml.getElementsByTagName('game')[0];
var team = game.getElementsByTagName('team')[0];
var score = team.getAttribute('score');

console.log(game, team, score);


seems to work fine, providing theXml is valid (which i forced it to be document)



hope this helps -ck


[#87259] Wednesday, February 22, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tiffany

Total Points: 46
Total Questions: 97
Total Answers: 84

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;