By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

HTML import

P: n/a
I've got this piece of code that imports an XML document ... it works
for both mozilla and IE.

function getXMl(url) {

if (!document.all) {
var xmlDoc = document.implementation.createDocument('','doc',nu ll);
var xmlHTTP = new XMLHttpRequest();
xmlHTTP.overrideMimeType("text/xml");
xmlHTTP.open("GET",url, false);
xmlHTTP.send(null);
xmlDoc=xmlHTTP.responseXML;
} else {
try {
xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
} catch (e) {
xmlDoc = new ActiveXObject("Msxml.DOMDocument");
}
xmlDoc.async="false";
xmlDoc.load(url);
}
return xmlDoc;
}

With mozilla i can use the same code to import an HTML file instead of
an XML file with no problems... but the object in IE expects a valid XML
file, so it does not work (xmlDoc.xml and xmlDoc.text gives me an
empty string output)...

Which is the object that will allow me to import an HTML file in IE?

thanks in advance.
alex.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


alex bazan wrote:
I've got this piece of code that imports an XML document ... it works
for both mozilla and IE.

function getXMl(url) {

if (!document.all) {
var xmlDoc = document.implementation.createDocument('','doc',nu ll);
var xmlHTTP = new XMLHttpRequest();
xmlHTTP.overrideMimeType("text/xml");
xmlHTTP.open("GET",url, false);
xmlHTTP.send(null);
xmlDoc=xmlHTTP.responseXML;
} else {
try {
xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
} catch (e) {
xmlDoc = new ActiveXObject("Msxml.DOMDocument");
}
xmlDoc.async="false";
xmlDoc.load(url);
}
return xmlDoc;
}

With mozilla i can use the same code to import an HTML file instead of
an XML file with no problems... but the object in IE expects a valid XML
file, so it does not work (xmlDoc.xml and xmlDoc.text gives me an empty
string output)...

Which is the object that will allow me to import an HTML file in IE?


You can use the download behavior with IE/Win if you want the text of an
HTML file, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/1268/fid/126>

There is also
new ActiveXObject('Microsoft.XMLHTTP')
which has the same API as XMLHttpRequest thus if for Mozilla
responseText gives you what you need then you could use

var httpReqest;
if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest();
}
else if (typeof ActiveXObject != 'undefined') {
httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
}
httpRequest.open('GET', url, true);
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4) {
// use httpRequest.responseText here
alert(httpRequest.responseText);
}
};
httpRequest.send(null);
--

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

P: n/a
En/na Martin Honnen ha escrit:


There is also
new ActiveXObject('Microsoft.XMLHTTP')
which has the same API as XMLHttpRequest thus if for Mozilla
responseText gives you what you need then you could use


thanks this worked!!
alex.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.