XpertWorlock Posted January 8, 2009 Share Posted January 8, 2009 I'm trying to get "type" into the XML "type", this doesn't work, but I think you can see what I am trying to do. I want x to be whatever type is. function loadParts(type) { xmlDoc.async=true; xmlDoc.load("./xml/parts.xml"); var x=xmlDoc.getElementsByTagName(type); } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 8, 2009 Share Posted January 8, 2009 can you post the rest of the code? where do you define xmlDoc? what "doesn't work" about it? Quote Link to comment Share on other sites More sharing options...
XpertWorlock Posted January 8, 2009 Author Share Posted January 8, 2009 If I write --> var x=xmlDoc.getElementsByTagName("example"); It works properly, I just want to have it so it retrieves the tag name whatever "type" is function loadParts(type) { try { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } catch(e) { try { xmlDoc=document.implementation.createDocument("","",null); } catch(e) { alert(e.message); return; } } document.getElementById("catalog").innerHTML = ""; xmlDoc.async=true; xmlDoc.load("./xml/parts.xml"); var x=xmlDoc.getElementsByTagName(type); for (i=0;i<x.length;i++) { document.getElementById("catalog").innerHTML = '<div style="position:relative; float:left; border:1px solid black; height:80px; width:80px;">' + x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue+ '</div>'; } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 8, 2009 Share Posted January 8, 2009 then i don't see why it wouldn't work...where is an example of you calling the function? is it just: loadParts('example'); Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 8, 2009 Share Posted January 8, 2009 also, try changing it async to false...otherwise it will try to parse the document before it's loaded: xmlDoc.async=false; Quote Link to comment Share on other sites More sharing options...
XpertWorlock Posted January 8, 2009 Author Share Posted January 8, 2009 I found out the problem, when the argument was put in loadParts(), the first letter was capitalized, everything in the XML file is lower case. So I just created a function to switch it to lower case for the loadParts(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.