473,507 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

innerHTML in IE7 writes malformed XHTML?

Is it me, or is innerHTML in IE7 (and as far as I can tell createNode
and importNode) rewriting the HTML to upper case and removing most of
the quotation marks? I am trying to copy XHTML into an XML document and
this makes for invalid XML so I can't transform it. Here is some test
code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="JavaScript" type="text/javascript">
function getSomeXml(id){

var xmlDoc= new ActiveXObject("Msxml2.FreeThreadedDOMDocument.5.0" );
xmlDoc.async = false;
xmlDoc.loadXML(document.getElementById(id).innerHT ML);

var stylesheet = new ActiveXObject("Msxml2.DOMDocument.5.0");
stylesheet.async = false
stylesheet.load("test.xslt");

if (stylesheet.parseError.errorCode != 0) {
var myErr = stylesheet.parseError;
alert("You have error " + myErr.reason);
}
else
{
alert("Look what innerHTML is doing to my stuff: " +
document.getElementById(id).innerHTML);
alert("This is what xmlDOc now contains: " + xmlDoc.xml)
}
}

</script>
</head>
<body>

<p><a href="javascript:getSomeXml('one')">Try with attributes</a></p>
<div id="one">
<div class="ihaveanattributeandwillscrewthisup">ooh la la!</div>
</div>

<p><a href="javascript:getSomeXml('two')">Try without
attributes</a></p>
<div id="two">
<div>ooh la la!</div>
</div>

</body>

I'd be grateful for any insights into this and especially for
workarounds.

Many thanks, Jeremy

Dec 12 '06 #1
4 4616
jottevan...@museumoflondon.org.uk wrote:
Is it me, or is innerHTML in IE7 (and as far as I can tell createNode
and importNode) rewriting the HTML to upper case and removing
most of the quotation marks?
Yes, the values read from innerHTML are generated from the HTML DOM
tree and in a browser dependent manner. IE uses the uppercase tag names
(as read from the - tagName - property of the Elements in the HTML DOM,
which are uppercase) and doesn't bother to quote attribute values that
do not need quoting.
I am trying to copy XHTML into an XML document and
this makes for invalid XML so I can't transform it.
<snip>

IE has no notion of XHTML, it is a (tag soup) HTML web browser (and
expecting to get XHTML from a property called innerHTML is a bit
unrealistic to start with).

Richard.

Dec 12 '06 #2
jo*********@museumoflondon.org.uk wrote:
Is it me, or is innerHTML in IE7 (and as far as I can tell createNode
and importNode) rewriting the HTML to upper case and removing most of
the quotation marks? I am trying to copy XHTML into an XML document and
this makes for invalid XML so I can't transform it.
IE (including IE 7) can only render XHTML when served as text/html
meaning your XHTML document is parsed with an HTML/SGML parser of the
browser and not an XML parser. The DOM built is a HTML DOM and innerHTML
is IE's way to serialize the contents of an element node in that DOM
back to HTML markup that follows HTML rules, not XML rules. In general
the HTML IE gives from innerHTML is not well-formed XML at all.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 12 '06 #3
Thank you Richard and Martin (Martin, you're very busy!)

Perhaps I need to play around some more with cloneNode etc., maybe I
was messing that up but I think it had the same result. No doubt IE
rewrites that too.

So next question: does anyone have a suggestion as to how I might be
able to get what should be a valid node-set from (X)HTML into an XML
doc?

Thanks once again,
Jeremy
Martin Honnen wrote:
IE (including IE 7) can only render XHTML when served as text/html
meaning your XHTML document is parsed with an HTML/SGML parser of the
browser and not an XML parser. The DOM built is a HTML DOM and innerHTML
is IE's way to serialize the contents of an element node in that DOM
back to HTML markup that follows HTML rules, not XML rules. In general
the HTML IE gives from innerHTML is not well-formed XML at all.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 12 '06 #4
jo*********@museumoflondon.org.uk wrote in news:1165932063.240923.244640
@j72g2000cwa.googlegroups.com:
Thank you Richard and Martin (Martin, you're very busy!)

Perhaps I need to play around some more with cloneNode etc., maybe I
was messing that up but I think it had the same result. No doubt IE
rewrites that too.

cloneNode will work fine, i use it all the time in IE/FF to add/remove form
elements and other things...
Dec 12 '06 #5

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

Similar topics

8
10876
by: Kyle | last post by:
I am presently making use of documentElement.innerHTML to retrieve page contents for manipulation, but I've noticed that the sting value returned is not identical to the actual page source....
14
2496
by: catorcio | last post by:
I'm trying to have some text in my page changed by clicking a button. Googleing around I've discovered that innerText doesn't work with every browser, so I've switched to innerHTML. It works fine...
10
2074
by: oopaevah | last post by:
When using innerHTML to insert xhtml IE5+ mangles the xhtml completely. For example it removes the quotes from attributes. It also does other ridiculous things like on a <div> it will insert the...
24
3473
by: bedhead | last post by:
Why doesn't a SELECT element's innerHTML reflected which option was selected? Works in IE. I need this functionality so that I can retain what choices a user made in a tabbed interface. ...
63
4691
by: Jake Barnes | last post by:
In the course of my research I stumbled upon this article by Alex Russel and Tim Scarfe: http://www.developer-x.com/content/innerhtml/default.html The case is made that innerHTML should never...
6
2980
by: sonic | last post by:
Ok, i am sure everyone is sick of hearing about this. but i've checked about 10 different posts/sites about this issue, and they all say "use DOM" but i think there is more to be said. Perhaps I...
4
8051
by: Dan Michael Heggå | last post by:
Hi, I've working on inplace-editing. My problem is the following: This works in all browsers: myDiv.innerHTML = "<p>...</p>"; but this doesn't work in IE: myDiv.innerHTML =...
2
3660
by: Denis McMahon | last post by:
Hi A relative has a web page that they want to work with google checkout, so it has to be xhtml, as the google scripts require xhtml. However, I wish to replace the text content of an id'd...
6
4205
by: PaPa | last post by:
I'm not sure this is a javascript issue or an HTML issue. I notice that when I extract the contents of a div using the innerHTML property (?), that I wind up with a literal variable (?) which...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.