parsing XML swapping nodes

I

ICPooreMan

I have a page which I'm trying to add ajax functionality to however I'm
having some difficulties.

Basically I have a section of my page that looks like this

<div id="pageDiv">
<!--a random amount of html could be several nodes of different
kinds-->
</div>

asynchronously my server returns
<document>
<pageDiv>
<!-- some random amount of HTML different than the original -->
</pageDiv>
</document
to sum up what I'm doing now when i get the callback is

div = document.getElementById("pageDiv");
repl = response.responseXML.getElementsByTagName("pageDiv")[0];
div.replaceChild(repl, div);

which will give me
<div id="pageDiv">
<pageDiv>
<!-- some random amount of HTML different than the original -->
</pageDiv>
</div>

It seems simple but I'm unable to figure out how to get the childNodes
of <pageDiv> into my other div. Any ideas of a better way to do this.
 
M

Martin Honnen

ICPooreMan said:
asynchronously my server returns
<document>
<pageDiv>
<!-- some random amount of HTML different than the original -->
</pageDiv>
</document
to sum up what I'm doing now when i get the callback is

If you put some elements in an XML document that have the same name as
defined HTML elements then nevertheless if parsed as XML the elements
are simple XML elements which just happen to have the same name as HTML
elements but the browser will not recognize and render them as HTML
elements. You either need to send some snippet of XHTML e.g.
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Kibology for all. <br/>All for Kibology.</p>
</div>
then when browsers like Mozilla or Opera parse that as XML they
recognize the elements in the XHTML 1 namespace
http://www.w3.org/1999/xhtml and you can import the nodes in the HTML
document using importNode. Or you need to take the XML markup and throw
it at the HTML parser, for instance by creating/using a HTML div element
and setting its innerHTML.
The XHTML way would be a good solution if IE supported it but as IE's
HTML DOM implementation and XML DOM implementation are separate ones you
can't use that approach with IE.
 
I

ICPooreMan

Thanks that really helps, I have another solution where I just take
whatever text is between the two tags and replace the elements
innerHTML with it, I'll probably just stick with that for now as it
works in IE, although that has problems with old versions of FF.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top