> (I supposed one can argue the intent of the W3C r.e. this line and > whether it would be applicable to injecting XHTML into another XHTML > document via AJAX; my point is merely that what I'm doing should not > be considered all that unusual.)
No "argument" need be made! Specs are not magnetic poetry: you can't take the existence of a spec for a full document, flip it around, and assume that allows you to nest entire documents inside other documents of that type, ad infinitum. Most blatant here, a document declaration is only allowed once per document. Period. There is no way to have a well-formed X(HT)ML document that has a declaration hanging out in the middle of the document. It is not simply a question of an out-of-place declaration being ignored: the construction <?xml ?> is totally invalid markup anywhere else. You're also trying to use DOM 2 (X)HTML to work with generic XML documents, an additional mismatch. The behavior of DOM methods when dealing with invalid (X)HTML is specifically left up to the User-Agent in the DOM 2 HTML spec. In sum, it *is* unusual to try to shoehorn (invalid) well-formed XML structure *inside* an existing HTML document, and there is no standard way that you should expect browsers to behave. That IE decides to interpret your injected document as a special XML object has its own consistency. Not that I agree with it -- I think a hard error should be thrown in all such cases -- but it is allowed to. You say other browsers deal with this "elegantly." Really? What do they do with your declaration? Do they silently delete it? What if the injected document has a different encoding from the parent -- does the parent encoding change to match the newest content? Which DTD is used? Whatever you think is elegant is just non-standard guesswork, and may not conform to a particular user's expectations any more than IE's behavior does. -- Sandy
