L
louissan
Hi all,
I'm coming across a problem, and really do not get where it comes
from.
The goal: to loop over attributes read from "object" nodes in an
imported XML file/flow (via XMLHTTP) and transform them into HTML/DOM
attributes.
The function ObjectList reads from the imported XML and calls the
needed functions to 'render' DOM nodes.
function objectList(object,usersrc) {
var attlist=new Array();
var objs = usersrc.getElementsByTagName(object);
for (i=0;i<objs.length;i++) {
alert(objs.length); // reads 5, but the loop stops at 0
var obj;
for (j=0;j<objs.attributes.length;j++) {
attlist[j]='"'+objs.attributes[j].nodeName+'|'+objs.attributes[j].nodeValue+'"';
}
var objType = objs.getAttribute('type');
if (objType=='anchor') obj = new anchor(attlist);
else {obj=null,alert('no type specified');}
// append child nodes
document.getElementById(objectListId).appendChild(obj);
}
}
The anchor function creates the node in the DOM
var a_att="..."; // list of valid W3C anchor attributes
function anchor(attlist) {
var att,attval;
newanchor = document.createElement('a');
for (i=0;i<attlist.length;i++) {
att = attlist.substring(1,(attlist.indexOf(sep)));
attval = attlist.substring(attlist.indexOf(sep)+1,attlist.length-1);
new Function ( 'if (a_att.indexOf(att)!=-1) {newanchor.' + att +
'="' + attval + '";}' );
}
var anchortext = new textNode('test');
newanchor.appendChild(anchortext);
return newanchor;
}
If my imported XML file looks like this:
<root>
<menu type="anchor" href="test.jsp" cssClass="top"
icon="test.gif">overview</menu>
<menu type="anchor" href="test.jsp" cssClass="top"
icon="test.gif">overview</menu>
<menu type="anchor" href="test.jsp" cssClass="top"
icon="test.gif">overview</menu>
<menu type="anchor" href="test.jsp" cssClass="top"
icon="test.gif">overview</menu>
<menu type="anchor" href="test.jsp" cssClass="top"
icon="test.gif">overview</menu>
</root>
The ObjetList loop stops at i=0. Why? Any clue?
Thanks
I'm coming across a problem, and really do not get where it comes
from.
The goal: to loop over attributes read from "object" nodes in an
imported XML file/flow (via XMLHTTP) and transform them into HTML/DOM
attributes.
The function ObjectList reads from the imported XML and calls the
needed functions to 'render' DOM nodes.
function objectList(object,usersrc) {
var attlist=new Array();
var objs = usersrc.getElementsByTagName(object);
for (i=0;i<objs.length;i++) {
alert(objs.length); // reads 5, but the loop stops at 0
var obj;
for (j=0;j<objs.attributes.length;j++) {
attlist[j]='"'+objs.attributes[j].nodeName+'|'+objs.attributes[j].nodeValue+'"';
}
var objType = objs.getAttribute('type');
if (objType=='anchor') obj = new anchor(attlist);
else {obj=null,alert('no type specified');}
// append child nodes
document.getElementById(objectListId).appendChild(obj);
}
}
The anchor function creates the node in the DOM
var a_att="..."; // list of valid W3C anchor attributes
function anchor(attlist) {
var att,attval;
newanchor = document.createElement('a');
for (i=0;i<attlist.length;i++) {
att = attlist.substring(1,(attlist.indexOf(sep)));
attval = attlist.substring(attlist.indexOf(sep)+1,attlist.length-1);
new Function ( 'if (a_att.indexOf(att)!=-1) {newanchor.' + att +
'="' + attval + '";}' );
}
var anchortext = new textNode('test');
newanchor.appendChild(anchortext);
return newanchor;
}
If my imported XML file looks like this:
<root>
<menu type="anchor" href="test.jsp" cssClass="top"
icon="test.gif">overview</menu>
<menu type="anchor" href="test.jsp" cssClass="top"
icon="test.gif">overview</menu>
<menu type="anchor" href="test.jsp" cssClass="top"
icon="test.gif">overview</menu>
<menu type="anchor" href="test.jsp" cssClass="top"
icon="test.gif">overview</menu>
<menu type="anchor" href="test.jsp" cssClass="top"
icon="test.gif">overview</menu>
</root>
The ObjetList loop stops at i=0. Why? Any clue?
Thanks