473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Adding nodes to custom tags

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
2 3427
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: alanrn | last post by:
I am using a TreeView to display the hierarchy of a strongly-typed collection (inherited from CollectionBase). The order of the nodes in the TreeView is strictly tied to the order in which they...
1
by: Todd | last post by:
I have the following code that inserts a new element and its attributes into an xml file. The problem is the syntax of the inserted row. here is my code: 'Create an XmlDataDocument. Dim doc As...
8
by: Paul J Lay | last post by:
I am trying to find nodes in an xml document using the XmlDocument class and having some problems. Everything seems to work OK when there are no encoded characters (< = &lt;) but when I try to...
8
by: fix | last post by:
Hi, I have an XML document and I need to add some attributes to an element. I use the XMLDocument object to load the xml file, and I can get the element I need to add attributes to in an...
3
by: Brian Henry | last post by:
If i already have a tree view created, and want to add another new node to it, how would i do so? Is there a way to throught tags or anything? like i have this RootNode | +-- Child 1 +--...
3
by: Papajo | last post by:
  I'd like to know how to add break tags "<br>" inbetween entry's in an input form, an example is if the word "yada yada" was entered you would wind up with y<br>a<br>d<br>a<br> y<br>a<br>d<br>a ...
9
by: gregmcmullinjr | last post by:
Hello, I am new to the concept of XSL and am looking for some assistance. Take the following XML document: <binder> <author>Greg</author> <notes> <time>11:45</time>
1
by: rohan_from_mars | last post by:
I have a windows service and am also using Enterprise Library June 2005 version. Now i have created Setup and Deployment Project which installs the service. but how do i add EL dlls-...
4
by: =?Utf-8?B?U2hhbmU=?= | last post by:
Hi all, Is it possible to add controls like buttons, textboxes etc to treeview nodes like this link: http://webui30.componentart.com/treeview/features/nesting_aspnetContent/WebForm1.aspx ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.