473,320 Members | 1,862 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,320 software developers and data experts.

parsing XML swapping nodes

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 <pageDivinto my other div. Any ideas of a better way to do this.

Jan 17 '07 #1
2 1446
ICPooreMan wrote:
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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 17 '07 #2
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.

Martin Honnen wrote:
ICPooreMan wrote:
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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christopher Jeris | last post by:
Please help me understand the differences, in semantics, browser support and moral preferredness, between the following three methods of swapping content in and out of a page via JavaScript. I...
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...
270
by: Jatinder | last post by:
I found these questions on a web site and wish to share with all of u out there,Can SomeOne Solve these Porgramming puzzles. Programming Puzzles Some companies certainly ask for these...
4
by: Erik Moore | last post by:
I am both producing and parsing an xml document that needs to be validated against a schema. I wanted some consumers of the document to have the option of not performing a validation, so I left the...
6
by: Hans Kamp | last post by:
Is it possible to write a function like the following: string ReadURL(string URL) { .... } The purpose is that it reads the URL (determined by the parameter) and returns the string in which...
4
by: Mike [MCP VB] | last post by:
Hi, I hope this is the right place to ask. I have an xml file thus: <?xml version="1.0" encoding="UTF-8"?> <Message xmlns="urn:myurl-org:ns2"...
2
by: nicky123 | last post by:
Hi everyone, This is a brief description that I have provided for parsing & displaying an XML document using DOM API. Please feel free to post your own comments & views regarding...
11
by: Juha Nieminen | last post by:
Assume we have this: std::list<Typelist1(10, 1), list2(20, 2); std::list<Type>::iterator iter = list1.end(); list1.swap(list2); What happens here, according to the standard? 1) 'iter'...
0
by: KUTTAN | last post by:
I have an xml file as follows <?xml version="1.0" encoding="utf-8" ?> <Nodes> <Nodes1> <siteMapNode title="Product Cataloge">
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.