Adding nodes to custom tags

A

alex bazan

I'm building a cross-browser XML dataisland.
This code works perfectly in mozilla, but i have problems with explorer.

it tells me that:
"diXML.getElementsByTagName(..).0 is null or not an object"

if i change my custom xml dataisland using <xml id="dataisland"></xml>
instead of the <div id="dataisland" ...> it shows a "type mismatch" error.

I have no problem accesing to the <di> tags inside the <table
id="dataisland_table">, so i can't see why i can't access them on the <div>.


Here is the code:

<script>

diFirstNode="di";
diItemNode="test";

function diXMLEdit (theForm,dI) {

diXML=document.getElementById(dI);
diForm=document.forms[dI+'_form'];
xmlElem=document.createElement(diItemNode);

for (i=0;i<theForm.elements.length;i++) {
if (theForm.elements.type!="button") {
if (diForm.dirow.value=="") {
xmlNode=document.createElement(theForm.elements.name);
xmlNode.innerHTML=theForm.elements.value;
xmlElem.appendChild(xmlNode);
} else {

}
}
}

if (diForm.dirow.value=="") {
diXML.getElementsByTagName(diFirstNode)[0].appendChild(xmlElem);
} else {

}
//diPopulate(theForm,dI);
}
</script>


<form name="dataisland_form">
<input type="hidden" name="dirow">
</form>

<div id="dataisland" style="display:none">
<di></di>
</div>

<table id="dataisland_table">
<tr id="dataisland_header">
<th>aa</th>
<th>bb</th>
<th>cc</th>
</tr>
<tr id="dataisland_schema" style="display:none">
<td><di field="aa"></di></td>
<td><di field="bb"></di></td>
<td><di field="cc"></di></td>
</tr>
</table>

<form name="myform">

<br><input type="text" name="aa">
<br><input type="text" name="bb">
<br><input type="text" name="cc">
<br><input type="button" value="go!"
onClick="diXMLEdit(document.myform,'dataisland')">

</form>
 
T

Thomas Hoheneder

diXML.getElementsByTagName(diFirstNode)[0].appendChild(xmlElem);

As far as I have tried it seems that there is no possibility to directly
access the <di> tag in "dataisland".
A work around of that would be adding the following lines of code BEFORE the
line shown above:

diXML.removeChild(diXML.firstChild);
var newDI = document.createElement("di");
diXML.appendChild(newDI);

This means: First remove the first child element <di> in "dataisland", then
re-add it with the appendChild method.
After this your appendChild of "test" won't cause any javascript error.

Hope this helps you.

Nice greetings from
Thomas
 
A

alex bazan

En/na Thomas Hoheneder ha escrit:
diXML.removeChild(diXML.firstChild);
var newDI = document.createElement("di");
diXML.appendChild(newDI);

This means: First remove the first child element <di> in "dataisland", then
re-add it with the appendChild method.
After this your appendChild of "test" won't cause any javascript error.

i've tried that but when i try to appendChild to 'di', it continues
failing me.

i've tried:
diXML.firstChild.appendChild(xmlElem);
diXML.getElementsByTagName(diFirstNode)[0].appendChild(xmlElem);

and none of them work.


BTW, i've got another approach which is working. It uses separate code
for moz and ie (though i never liked doing this kind of code).

if (!document.all) {
diXML=document.getElementById(dI);
xmlElem=document.createElement(diItemNode);
} else {
diXML=document.all(dI).XMLDocument;
xmlElem=diXML.createElement(diItemNode);
}

thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top