XML file in Javascript, getElementByAttribute

gavalkad

New Member
Let's suppose I have an XML file like this:\[code\]<?xml version="1.0" encoding="ISO-8859-1"?><MIDIFile> <Event> <Absolute>0</Absolute> <NoteOn Channel="1" Note="40" Velocity="64"/> </Event> <Event> <Absolute>236</Absolute> <NoteOff Channel="1" Note="40" Velocity="0"/> </Event></MIDIFile>\[/code\]Thanks to some great tutorial I now know how to get these values in my javascript.For example, I can iterate thru all the "Events" tag and get the "Absolute" value like this:\[code\]xmlhttp=new XMLHttpRequest();xmlhttp.open("GET","test.xml",false);xmlhttp.send();xmlDoc=xmlhttp.responseXML;// make an array with all the events from the xml filevar events = xmlDoc.getElementsByTagName("Event")for (var i = 0; i<events.length; i++)console.log(events.getElementsByTagName("Absolute")[0].childNodes[0].nodeValue)\[/code\]this will return\[code\]0236\[/code\]Now, how the hell can I access the "NoteOn" attribute and get its values? I want to iterate thru all the Events in the XML, see if they contains NoteOn or NoteOff and load an array with all the notes, their duration, velocity and channels.Please help me! \[code\]getElementsByTagName("NoteOn")\[/code\] just doesn't work... If it might help, here are some screenshot of what happens if I \[code\]console.log(xmlDoc)\[/code\]Thanks a lot in advance!
Dnhz7.png
edit in response to an answer. As I try to do this:\[code\]var noteon = xmlDoc.getElementsByTagName('noteon');console.log(noteon)\[/code\]the result is just this one\[code\][]\[/code\]re-edit:If I write "NoteOn" instead of "noteon" it works!
 
Back
Top