Jump to content

Problem Extracting from XML in Chrome


spencerl

Recommended Posts

Hello,I'm having trouble with the following code in Chrome:function loadXMLDoc(dname) {if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xhttp.open("GET",dname,false);xhttp.send(null);return xhttp.responseXML;}function loaddatabase(){xmlDoc=loadXMLDoc("database.xml");x=xmlDoc.getElementsByTagName("item");for (i=0;i<x.length;i++) { z=i+1 t=x.nodeName document.write(t+" "+z+"<br \>"); y=xmlDoc.getElementsByTagName("item").childNodes; for (ii=0;ii<y.length;ii++) { document.write(y[ii].nodeName); if (y[ii].attributes.length>0) { document.write(" "+y[ii].attributes[0].name+"("+y.item(ii).attributes[0].nodeValue+")"); } document.write(": "+y[ii].childNodes[0].nodeValue+"<br \>"); } document.write("<br \>"); }}The code outputs this in IE7 but not in Chrome:item 1name: Ankigroup: Alltag level(1): Softwaretag level(2): Flash Cardslink: http://ichi2.net/anki/item 2name: AP Tunergroup: Alltag level(1): Softwaretag level(2): Musiclink: http://www.aptuner.com/item 3name: AV-Comparativesgroup: Alltag level(1): Websitetag level(2): Antiviruslink: http://www.av-comparatives.org/In Chrome it looks like this:item 1#text What is the solution to this? Thank you for the help.

Link to comment
Share on other sites

It will do the same in Firefox also. I'll bet your XML files are all "pretty-printed," meaning they have line breaks and indentations. Some xml parsers will ignore that. Others will consider the tabs and stuff to be a text node. That's why it prints #text, and then breaks when asked to examine the length of an attributes property that it does not have.Try adding this line to the top of your for-loop:if (y[ii].nodeName == "#text") continue;

Link to comment
Share on other sites

It will do the same in Firefox also. I'll bet your XML files are all "pretty-printed," meaning they have line breaks and indentations. Some xml parsers will ignore that. Others will consider the tabs and stuff to be a text node. That's why it prints #text, and then breaks when asked to examine the length of an attributes property that it does not have.Try adding this line to the top of your for-loop:if (y[ii].nodeName == "#text") continue;
I removed all the breaks and spaces from my xml document and it worked and then I also tried that line of code you gave me which also worked great. Thanks for the help!I also noticed that when I try to set the size of a selection list it is always set to 4 in chrome. Is there a solution to this as well? My code looks like this:<form><select size="2"></select></form><form><select size="3"></select></form>But I just get a selection list with a size of 4 no matter what.
Link to comment
Share on other sites

Are you also setting the height in CSS, or the height of a parent element?
I haven't written any CSS yet and I haven't set the height anywhere yet. I haven't set the height of any elements at all. I've just used the size attribute and just for that element.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...