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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending XML containing HTML to a page.

Status
Not open for further replies.

mterrey

Programmer
Joined
May 16, 2006
Messages
3
Location
GB
Hi,

I have started using xmlhttprequests and post data to a server side program that then generates XML and sends it back to the page. The XML is actually something like this:

<xmldata>
<tbody>
<tr id="row1" onClick="rowSelect(1,'0x000eac01');">
<td id="row1cell1" bgcolor="#b7bceb">000000317</td>
<td id="row1cell2" bgcolor="#a8adde">Al</td>
</tr>
</tbody>
</xmldata>

As you can see, apart from the <xmldata> tags its HTML, and I basically want to attach this HTML into the document as it is. I assumed I could get all the nodes under <xmldata> and append it to my HTML in Javascript like so:

var oNewNode = theXML.getElementsByTagName('xmldata')[0];
timesheetbody.appendChild(oNewNode);

Unfortunately all this seems to do is throw all of the text from each of the tags into one cell, so from the above example I get "000000317 Al" in the cell. Rather than attaching the actual HTML.

Anyone got any ideas?

Thanks,
Mark
 
I have no experience with XML but I think your approach is close. Try creating the new node first and then assigning the xml information into the innerHTML property of the new node with something like: timesheetbody.innerHTML = xmldata;


It's hard to think outside the box when I'm trapped in a cubicle.
 

Thanks for the suggestion theniteowl... If I understand you correctly are you saying do something like this?

var oNewNode = theXML.getElementsByTagName('xmldata')[0];
timesheetbody.innerHTML=oNewNode;

Unfortunately that returns: [object Element] - as the node is an XML element.



 

Thanks for your help everyone, in the end I decided to send HTML back as responseText instead of responseXML and just assign it to the innerHTML as suggested. There was no real advantage in me using XML for this anyway.

Thanks again!
 
I really need to start learning XML but there are so many other things I "really" need to start learning that I have just not had the oppurtunity.


It's hard to think outside the box when I'm trapped in a cubicle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top