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

innerHTML mangles the xhtml


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 enbedded
style="DISPLAY:BLOCK"! This is a documented feature you can find in
msdn.

Is there a way to disable this quite appalling feature?

Jul 23 '05 #1
10 2070


oo******@yahoo.co.uk wrote:
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 enbedded
style="DISPLAY:BLOCK"! This is a documented feature you can find in
msdn.

Is there a way to disable this quite appalling feature?


IE is known not to be able to handle XHTML as real XML, all it can do is
treat it as HTML. innerHTML is doing stuff which is allowed in HTML but
not in XHTML so you have just one more reason to avoid using XHTML, see
<http://www.hixie.ch/advocacy/xhtml>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

IE can render xhtml perfectly, otherwise we wouldn't be having the
welcome surge of web standards compliance, and besides xhtml is just
clean html anyway. Maybe I misunderstand your point can you elaborate?

If I put the same xhtml into the page manually it renders perfectly,
when I put it through innerHTML IE deliberately alters the markup prior
to rendering. Surely IE uses the same engine to display the original
xhtml I send from the server as it does to render innerHTML? Sounds
like innerHTML is useless to me and many web developers who need to use
xhtml.

Jul 23 '05 #3
I've done more testing. If I do an alert() on the innerHTML of a div
which contains normal static xhtml then it displays it mangled which
suggests that innerHTML is not the problem but IE's interpretation of
x/html is the problem which is probably what you meant.

If IE parses all structure elements prior to rendering to suit its own
rendering engine then no wonder it is slower than the likes of Firefox.

Jul 23 '05 #4
oo******@yahoo.co.uk wrote:
IE can render xhtml perfectly
No, it can't. It asks users if they want to download XHTML documents. That
can hardly be described as rendering at all.
otherwise we wouldn't be having the welcome surge of web standards
compliance
We are experiencing a surge of authors jumping on the XHTML bandwagon with
no apparent idea that true XHTML is not viable at this time, mainly due to
the lack of support from Microsoft.

There is just as much non-semantic, bloated rubbish being pumped out now as
there always has been. The only difference is that now it might be written
in XHTML, and might pass automated validation. That doesn't necessarily
make it either standards-compliant, or truly valid.
and besides xhtml is just clean html anyway.
Nonsense. My HTML markup is just as 'clean' as anyone else's XHTML. More so
in some cases. HTML authors don't /have/ to quote all attributes, or use
optional opening and closing tags, but there's no reason why they can't.
Yes, XML enforces these things, but so can just a touch of personal
discipline (or a custom DTD, if that is too much to ask).
Maybe I misunderstand your point can you elaborate?
The vast majority of XHTML documents - the result of your 'surge' - are
transmitted incorrectly as HTML. Either the Content-Type header, or a META
element, will indicate text/html instead of application/xhtml+xml. User
agents dutifully respect what they're told and parse the markup as really
badly written HTML, not XHTML. This is why IE is seen to parse it, when in
reality, it doesn't at all; it just performs a lot of error correction.

A Google search will tell you all of this. Searching for application/xhtm
+xml will also probably raise some useful discussions.
If I put the same xhtml into the page manually it renders perfectly,
when I put it through innerHTML IE deliberately alters the markup prior
to rendering.
I would expect all user agents to perform some form of normalisation on
markup before attempting to run it through a parser. It might do things
like collapse white space, add or strip quotes, etc. Anything to make life
easier for the parser.
Surely IE uses the same engine to display the original
xhtml I send from the server as it does to render innerHTML?
IE doesn't understand XHTML so when it performs the preprocessing above, it
does things contrary to XML syntax rules.
Sounds like innerHTML is useless to me
Didn't Martin say that?
and many web developers who need to use xhtml.


I doubt that many Web developers /need/ to use XHTML at all.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
> It might do things like collapse white space,

Yes. IE does this even when you're changing the innerHTML of a <pre>
element, which is a disaster.

--Phil.

Jul 23 '05 #6
On 18 May 2005 01:40:17 -0700, oo******@yahoo.co.uk wrote:

IE can render xhtml perfectly, otherwise we wouldn't be having the
welcome surge of web standards compliance, and besides xhtml is just
clean html anyway.
XHTML is not just clean HTML, it's built on completely different
foundations.
If I put the same xhtml into the page manually it renders perfectly,
when I put it through innerHTML IE deliberately alters the markup prior
to rendering.
no, all mark-up languages are simply a representation of a particular
infoset, you can serialise that infoset in lots of ways, in html, or
xhtml, or ... the innerHTML etc. properties are serialisations in
IE's format, that format is basically an HTML one - it is not an XHTML
one, and there is no reason why it should serialise its normalised
version of the infoset as XHTML.
Surely IE uses the same engine to display the original
xhtml I send from the server as it does to render innerHTML? Sounds
like innerHTML is useless to me and many web developers who need to use
xhtml.


You've yet to adequately explain why you, or anyone else would need to
use xhtml, and you've also failed to explain why you need the
normalised serialisation of the infoset in a particuly format -
neither of these things are ever likely to be a good idea, I've never
come across a situation without a better solution.

What's you situation?

Jim.

Jul 23 '05 #7
<oo******@yahoo.co.uk> wrote [...]
IE can render xhtml perfectly,


No, it can *not*. What in fact is rendered is falsely error-corrected
HTML. A strong indication that IE does not support XHTML to date is
that it does not support (tries to download as file rather than
rendering it) the standardized MIME type for *plain* XHTML 1.0 (optional,
although that allowance is based on the same flawed compatility
guidelines as the error correction) and XHTML 1.1 (mandatory, i.e. MUST
NOT be served otherwise), application/xhtml+xml, while e.g. Gecko-based
UAs do.
PointedEars

Jul 23 '05 #8
Thanks for the replies everyone.. I learned a lot from what you've said
and it's spurred a load of research on my part..

IE is worse than I thought..

The reason I need to use xhtml is because of web standards. Some of our
customers are demanding web standards for good reason, and our
competitors provide web standards solutions so xhtml (and other web
standards aspects of development) makes business sense, faster
rendering in modern browsers, future proof markup etc.. As long as I
provide xhtml I am doing all I can and can only wait until ie catches
up.

Jul 23 '05 #9
oo******@yahoo.co.uk wrote:
The reason I need to use xhtml is because of web standards.
When did HTML stop being a standardised Web technology? As I wrote in a
previous post, nothing makes HTML a lesser language. Nothing stops an
author from writing compact, semantic, and accessible markup in HTML. I
think you're just listening to hype.
[...] faster rendering in modern browsers,
Rendering XHTML as HTML is undoubtably slower in /any/ user agent as they
will all have to perform error correction. Yes, even Opera and Mozilla
perform error correction as you told them they're receiving HTML.

If you were serving XHTML as XHTML, then your argument is valid as an XHTML
parser can make certain assumptions about form that tag soup parsers
cannot. But, you're not.
future proof markup
HTML isn't going anywhere for a very long time.
[...] wait until ie catches up.


Even if Microsoft implements an XHTML parser in some future version, XHTML
will still fail to be viable as most of the user agents in use will still
only parse HTML.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #10
You go your way I'll go mine.

Jul 23 '05 #11

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

Similar topics

14
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...
6
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
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 =...
4
by: jottevanger | last post by:
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...
2
by: ars | last post by:
hi everyone i'm using some regular expression to paging, it work's fine in IE but not in Firefox i removed every thing to detect problem but i Can't , the only thing i got, is the innerHtml doent...
7
by: Lorenzo Bettini | last post by:
Hi on the same page I set the innerHTML property of an element to something like my_string + "<br />" then when I try to remove my_string + "<br />" from the innerHTML it fails since the...
6
by: cantrell78 | last post by:
I can't for the life of me figure out how to execute javascript inside of div that was set using innerHTML or in my case using cloneNode and replaceChild (not my idea to do this, I'm just fixing...
2
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.