HTML import

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alex bazan

    HTML import

    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.implem entation.create Document('','do c',null);
    var xmlHTTP = new XMLHttpRequest( );
    xmlHTTP.overrid eMimeType("text/xml");
    xmlHTTP.open("G ET",url, false);
    xmlHTTP.send(nu ll);
    xmlDoc=xmlHTTP. responseXML;
    } else {
    try {
    xmlDoc = new ActiveXObject(" Msxml2.DOMDocum ent");
    } catch (e) {
    xmlDoc = new ActiveXObject(" Msxml.DOMDocume nt");
    }
    xmlDoc.async="f alse";
    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.
  • Martin Honnen

    #2
    Re: HTML import



    alex bazan wrote:
    [color=blue]
    > 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.implem entation.create Document('','do c',null);
    > var xmlHTTP = new XMLHttpRequest( );
    > xmlHTTP.overrid eMimeType("text/xml");
    > xmlHTTP.open("G ET",url, false);
    > xmlHTTP.send(nu ll);
    > xmlDoc=xmlHTTP. responseXML;
    > } else {
    > try {
    > xmlDoc = new ActiveXObject(" Msxml2.DOMDocum ent");
    > } catch (e) {
    > xmlDoc = new ActiveXObject(" Msxml.DOMDocume nt");
    > }
    > xmlDoc.async="f alse";
    > 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?[/color]

    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.XMLHT TP')
    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.XMLHT TP');
    }
    httpRequest.ope n('GET', url, true);
    httpRequest.onr eadystatechange = function () {
    if (httpRequest.re adyState == 4) {
    // use httpRequest.res ponseText here
    alert(httpReque st.responseText );
    }
    };
    httpRequest.sen d(null);


    --

    Martin Honnen

    Comment

    • alex bazan

      #3
      Re: HTML import

      En/na Martin Honnen ha escrit:[color=blue]
      >
      >
      > There is also
      > new ActiveXObject(' Microsoft.XMLHT TP')
      > which has the same API as XMLHttpRequest thus if for Mozilla
      > responseText gives you what you need then you could use[/color]

      thanks this worked!!
      alex.

      Comment

      Working...