I have a project where I want to treat XHTML as XML. Which should be trivial because XHTML is XML – and it is trivial with FireFox.
However I have been experimenting with Microsoft Expression Web as my primary HTML/CSS editor – simply because of its awesome CSS re-factoring ability.
However I have run into an issue.
For XHTML to be parseable as XML with the browser XmlDocument/Msxml2.DOMDocument object, I need the XML to be well formed. From experiment it looks like with IE I need to include the
xml prolog xml-declaration <?xml version=”1.0″ … ?> directive at the start before the DOCTYPE or any processing instruction or the document does not parse.
According to the W3 XML Spec – the xml prolog should be optional, and if this worked in practice then I would have no issue – but it seems that the IE Msxml2.DOMDocument object will not load XML if you don’t have the
xml prolog xml-declaration before the DOCTYPE.
So I am forced to add it. And according to the XML spec that’s not only just fine, its recommended.
But If I do that – in Microsoft Expression Web I get the following.
Its telling me I need to make my XHTML badly formed! I can only assume that despite having the perfectly legal
xml prolog xml-declaration – its not recognising the DOCTYPE.
Could it be that the code to detect the DOCTYPE is not allowing for the
xml prolog xml-declaration like it was with an previous issue in IE6?
Changing it to
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" ></meta>
Just seems to bring on another error.
It also forces me into IE6 rendering mode (Which I suspect is a kind of Quirks mode).
In that mode CSS does not work as expected.
If I remove the xml-declaration <?xml version=”1.0″ encoding=”UTF-8″?> then it works – but my XHTML is now not XML (according to Msxml2.DOMDocument ) and I can’t process it in any of the browsers XMLDocument objects without getting errors.
So I can’t use Expression Web to edit any of my XHTML.
If I can’t find a fix for this (or an explanation as to what I am doing wrong), I’m going to have to revert back to using FireFox and Firebug for all my CSS work.
I’m going to attack this from the angle of getting the Msxml2.DOMDocument in IE to parse the XML with the DOCTYPE at the start (no xml-declaration) – perhaps there is a workaround there.
It seems to work fine in FireFox.
Try double clicking the "IE6" status bar pain at the bottom right and change your secondary schema to be XHTML 1.0 strict. This seems to resolve the issue you’re having with Expression Web. Let me know if this works for you.
Note however that occassionally you will need to reset this value (and the primary schema) as it will change as you create new pages.
Hope this helps,
That should have said status bar "pane"… perhaps I’ve done too much UI work lately 🙂
"I need to include the xml prolog <?xml version="1.0" … ?> directive" and "…will not load XML if you don’t have the xml prolog before the DOCTYPE"
ASIDE: you seem to be referring to the "XML prolog" when you actually mean XML Declaration. An XML Prolog includes the DOCTYPE (also any white space, comments, PI’s etc – see your link to the XML spec).
I don’t think your issue is with the DOCTYPE, I think it’s more likely caused by the fact that IE is trying to guess the mime type and treating it is as text/html unless it sees the XML Declaration. Normally to get IE to see XML you have serve it as application/xml… (you could also try changing the file extension to .xml)
I solved your Expression Web problem by changing the "Page Editor" properties from the default "Secondary Scheme: Internet Explorer 6.0" to "Secondary Scheme: XHTML 1.0 Strict". I was then able to add a XML declaration and have Intellisense provide correct code tips.
From the menu choose Tools -> Page Editor then from the "Authoring" tab of the dialogue change the "Secondary Scheme" setting.
This is only the second time I’ve opened Expression Web so I can’t vouch that this isn’t the worst thing you could do… good luck.
JD: Yes – I used the term xml-prolog – what I meant was xml-declaration,
Chris/JD: Yep I set the secondary scheme to XHTML 1.0 Strict – this solved the rendering issue in MEW preview – I was hoping there was some way to get MEW to recognise the official XML syntax. But a workaround is a workaround 🙂
Chris: changing the extension to .xml seemed to make no difference 😦
I’m going to construct a minimal testcase of loading the XML sans xml-declaration into Msxml2.DOMDocument and work out what the issue is there. I’m hoping that one of the versions will parse it – then I need to work out if its acceptable to rely on that version being installed.
Did you try setting the Mime type?
Response.contentType = "text/xml"
Wow, thats a really clever way of thniking about it!
I also had a lot of complicate problems with IE6 and with other browsers like Firefox, Opera and Safari it worked without any problem. I fixed some of them but other I rejected and ignored since 80% of my visitors use other browsers than IE6.