By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,028 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,028 IT Pros & Developers. It's quick & easy.

Adding nodes to custom tags

P: n/a
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[i].type!="button") {
if (diForm.dirow.value=="") {
xmlNode=document.createElement(theForm.elements[i].name);
xmlNode.innerHTML=theForm.elements[i].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>
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> 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
Jul 23 '05 #2

P: n/a
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.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.