views:

293

answers:

2

I have an HTML form and iframe like this:

<form id="frmUpload" target="ifrTarget" action='http://....asmx/SampleMethod'&gt;
  <input name="title" /><br />
  ...
  <input type="submit"/>
</form>
<iframe id="ifrTarget" name="ifrTarget"></iframe>

Action attribute points to my ASP.NET web service. When the form is submitted, the IFRAME gets filled with the resulting XML. I need to retrieve DOM of this XML document. So far my code looks like this:

var iframe = document.getElementById("ifrTarget");
var root = iframe.contentWindow.document.documentElement;

This works perfectly in FireFox, Chrome and Opera browsers. But it doesn't work in IE 6 & 7. As far as I understand, in IE I get DOM of the HTML document which IE builds internally to display syntax highlighting for XML. What I need is to get underlying XML unmodified. Is it achievable in IE?


There is a strong reason to stick with form and iframe rather than call web service via AJAX. Unfortunately, AJAX is not an option for me in this particular case.

A: 

No, you cannot get the unmodified XML in this manner with IE. The XML "pretty printer" MIME filter will replace the XML source as seen by IE with the HTML the user is shown.

Using XHR or the like is the only real workaround.

EricLaw -MSFT-
A: 

Try to associate the XML going to IFRAME with (even non-existing) CSS. This should prevent IE from pretty printing the XML. Then the contentWindow.document should contain DOM of received XML. Or you may want to retrieve document content as string and parse the string as XML. CSS is associated with XML by processing instruction as follows:

<?xml-stylesheet href="nonexistent.css" type="text/css"?>

st33ve