Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically either Create or Copy XML in javascript

Status
Not open for further replies.

LovinIt

Programmer
Dec 20, 2004
17
US
Hi all I need a little help here.

I am using a third party control. And with that I am creating lines in my form dynamically through DOM.

The third party ASP/Javascript control uses xml data islands persae(hope that is the right word) to reference the data. Such as what is seen below.

<xml id="xmlAcctCodes" src="getAcctCodes.asp"></xml>

For each new line there is a new control that needs a new xml dataisland created.

So, what I need to do is either create a new XML data island from scratch via javascript or clone one that is already loaded and append it to the body area.

I have tried to do this but have run into issues:

Attempt #1:
This does create the XML node as needed. However, what happens is it is too slow too load. As in by the time it gets to where I am creating and initializing the third party control the XML doc hasn't loaded yet. If I put an alert after this code and wait a few seconds and then click ok to continue it works.

So with this example, I need a way to make it not continue until the XML tag has finished loading the page.
Code:
var oXMLAcct;
oXMLAcct = document.createElement("<XML id='xmlAcctCodes" + iLineCount + "' src='getAcctCodes.asp' />");
document.body.insertBefore(oXMLAcct);

Attempt #2:
Cloning works part way. Except Two things:
1) I can't assign the ID value, which is an issue. I have tried two ways.
2) the insertBefore statement bombs. Telling me that no such interface is supported
Code:
var oXMLAcct;
var cCMLAcct = document.getElementById('xmlAcctCodes');
oXMLAcct = cCMLAcct.cloneNode(true);
//Two different way I tried assigning the id
oXMLAcct.id =  'xmlAcctCodes' + iLineCount;
oXMLAcct.documentElement.id =  'xmlAcctCodes' + iLineCount;
//This line bombs.  I have also tried appendChild with the same result.
document.body.insertBefore(oXMLAcct);

Any help at getting this to work is greatly appreciated.

I have to be able to do it this way as I do not have the ability to change the Third party code and the way it works.

Many thanks,

Angela
 
I got it to work.

But would appreciate opinion about how I did it and whether or not it might cause problems down the road?

This is it:

Code:
var oXMLAcct;
oXMLAcct = document.createElement("<XML id='xmlAcctCodes" + iLineCount + "' src='getAcctCodes.asp' />");
oXMLAcct.async = false;
oXMLAcct.load('getAcctCodes.asp');
document.body.insertBefore(oXMLAcct);

What yah think?

Angela
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top