W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2001

Re: how can I dynamically instantiate Elements with the Dom?

From: Jeff Yates <PBWiz@mail.pbwizard.com>
Date: Wed, 1 Aug 2001 13:21:01 -0400
Message-Id: <200108011321.AA2953576606@mail.pbwizard.com>
To: <www-dom@w3.org>, Irene Markelic <markelic@uni-koblenz.de>
Irene,

You can do it as follows:

Fault.appendChild( Analysis.cloneNode(true) );


Jeff.



---------- Original Message ----------------------------------
From: Irene Markelic <markelic@uni-koblenz.de>
Date: Wed, 01 Aug 2001 11:33:10 +0200

Hello!

 I really need help. In order to create my own dom-tree I happily
instantiated elements. But now I came to the point where its getting
quite difficult.
Imagine you have an xml-document with the following tags:

<Analysis Name="bla" Type="blabla" >
<Analysis Name="blu" Type="blublu" >
<Analysis...

The problem is that I never know how many Analysis Elements I have to
instantiate, so I will put it in a loop. But then of course the next
problem occurs. I cannot name the elements differently.
I tried it this way:

while( i!= 0){
	Element Analysis = domDocument.createElement("Analysis");
	Fault.appendChild(Analysis);
}

obviously this doesnt work.

So the next thing I tried was:

while( i!=0){
	Fault.appendChild(Analysis);
}

I thought this would attach the Analysis-Element i-times to the
Fault-Element. But it did it only once!
It seems like it is not possible to attache one Element twice to the
same tree.
Why?

And even more important, does anybody have a clue how I could solve this
problem?
I really dont know further.

hoping for any answers and your knowledge,

Irene



--
Jeff Yates
e-mail:    PBWiz@PBWizard.com
Homepage:  http://www.PBWizard.com

--
Received on Wednesday, 1 August 2001 13:28:58 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:49 GMT