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(obje ct,usersrc) {
var attlist=new Array();
var objs = usersrc.getElem entsByTagName(o bject);
for (i=0;i<objs.len gth;i++) {
alert(objs.leng th); // reads 5, but the loop stops at 0 :(
var obj;
for (j=0;j<objs[i].attributes.len gth;j++) {
attlist[j]='"'+objs[i].attributes[j].nodeName+'|'+o bjs[i].attributes[j].nodeValue+'"';
}
var objType = objs[i].getAttribute(' type');
if (objType=='anch or') obj = new anchor(attlist) ;
else {obj=null,alert ('no type specified');}
// append child nodes
document.getEle mentById(object ListId).appendC hild(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.create Element('a');
for (i=0;i<attlist. length;i++) {
att = attlist[i].substring(1,(a ttlist[i].indexOf(sep))) ;
attval = attlist[i].substring(attl ist[i].indexOf(sep)+1 ,attlist[i].length-1);
new Function ( 'if (a_att.indexOf( att)!=-1) {newanchor.' + att +
'="' + attval + '";}' );
}
var anchortext = new textNode('test' );
newanchor.appen dChild(anchorte xt);
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(obje ct,usersrc) {
var attlist=new Array();
var objs = usersrc.getElem entsByTagName(o bject);
for (i=0;i<objs.len gth;i++) {
alert(objs.leng th); // reads 5, but the loop stops at 0 :(
var obj;
for (j=0;j<objs[i].attributes.len gth;j++) {
attlist[j]='"'+objs[i].attributes[j].nodeName+'|'+o bjs[i].attributes[j].nodeValue+'"';
}
var objType = objs[i].getAttribute(' type');
if (objType=='anch or') obj = new anchor(attlist) ;
else {obj=null,alert ('no type specified');}
// append child nodes
document.getEle mentById(object ListId).appendC hild(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.create Element('a');
for (i=0;i<attlist. length;i++) {
att = attlist[i].substring(1,(a ttlist[i].indexOf(sep))) ;
attval = attlist[i].substring(attl ist[i].indexOf(sep)+1 ,attlist[i].length-1);
new Function ( 'if (a_att.indexOf( att)!=-1) {newanchor.' + att +
'="' + attval + '";}' );
}
var anchortext = new textNode('test' );
newanchor.appen dChild(anchorte xt);
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 :)
Comment