innerHTML in IE7 writes malformed XHTML?

J

jottevanger

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).innerHTML);

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
 
R

Richard Cornford

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.
 
M

Martin Honnen

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.
 
J

jottevanger

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
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,267
Latest member
WaylonCogb

Latest Threads

Top