migroo Posted November 1, 2009 Report Share Posted November 1, 2009 Okay so I was looking at the XML application Part in the XML tutorial and I have a few questions.Here is the link to the lesson: http://w3schools.com/xml/xml_applications.aspHere is the code that they give: <html><head><script type="text/javascript">var xmlDoc;if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); }else // Internet Explorer 5/6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xhttp.open("GET","cd_catalog.xml",false);xhttp.send("");xmlDoc=xhttp.responseXML;var x=xmlDoc.getElementsByTagName("CD");i=0;function display(){artist=(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);title=(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);year=(x[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue);txt="Artist: " + artist + "<br />Title: " + title + "<br />Year: "+ year;document.getElementById("show").innerHTML=txt;}</script></head><body onload="display()"><div id='show'></div></body></html> Now in the head they have this:var x=xmlDoc.getElementsByTagName("CD");i=0;function display(){artist=(x.getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);title=(x.getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);year=(x.getElementsByTagName("YEAR")[0].childNodes[0].nodeValue);txt="Artist: " + artist + "<br />Title: " + title + "<br />Year: "+ year;document.getElementById("show").innerHTML=txt;}What does the variable "i" do?What is "X" mean? I assume that it means what ever "X" is with a value of what ever the variable "i" is.What do the "+" signs on either side of artist, title, and on one side of year do?And last of all what does .innerHTML=txt mean?I am trying to understand why these things are not just that they are so I can write better coding in the future. Thanks Link to comment Share on other sites More sharing options...
boen_robot Posted November 1, 2009 Report Share Posted November 1, 2009 You should learn JavaScript (and btw, this question should've been there). The W3Schools JavaScipt tutorial explains all of your questions and more.But anyway: What does the variable "i" do?It stores a value, like every variable... the number "0" in this case.What is "X" mean? I assume that it means what ever "X" is with a value of what ever the variable "i" is. The "x" variable contains a NodeList object, which is accessible like an array. See the JavaScript tutorial if you don't know what an array is and how it is used.What do the "+" signs on either side of artist, title, and on one side of year do? with numbers, as you may guess, it sums them. With strings (as in this case), it concatenates them. "a" + "b" would result in "ab".And last of all what does .innerHTML=txt mean? The contents of the targeted HTML element (its "inner HTML") is set to be the same as the value of the "txt" variable. Link to comment Share on other sites More sharing options...
migroo Posted November 1, 2009 Author Report Share Posted November 1, 2009 Okay thanks! Sorry, I must just missed the answers in the javascript section. I am new to programing so I still don't know all that much yet. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now