Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Load HTML-Document into DOM

    Hi,

    I´m trying to load a HTML-Document to read the <p>-Tag (for PDF-Export).

    The link to the index.html is embded in a xml-element. Don´t know how to execute the link to get the HTML-file but on the first step I try to read the content of the html-file.
    With the following code, I get the content as a stream:
    function Textstream() {
    var fso, f, ts;
    var ForReading = 1;
    var TristateUseDefault = -2;

    fso = new ActiveXObject("Scripting.FileSystemObject");
    f = fso.GetFile("c:\\index.html");

    ts = f.OpenAsTextStream(ForReading, TristateUseDefault);
    s = ts.ReadAll( );
    alert(s);
    }
    But i would like to load the index.html into a DHTML DOM an read the Tags with:
    document.all.tags("p");
    Thanx !

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    the collection of all the <p> tags is referenced as

    document.getElementsByTagName('p')

    to work with it you should circle

    var oPar = document.getElementsByTagName('p')
    for(var i =0;i<oPar.length;i++){
    ... do something with oPar[i]....
    }
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanx for your reply !
    But I need to read the <p>-Tag from several html-documents. So I wanted to refer the index.html to the DOM of DHTML.

  • #4
    Regular Coder
    Join Date
    Aug 2005
    Posts
    282
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you could temporarily load each file into an iframe element of your page.
    that way it is a disconnected DOM that you simply are using to "scrape" the contents of.

    Code:
    <iframe id="HTMLParser"/>
    
    function getDOM(src, onload) {
      var parser = document.getElementById("HTMLParser");
      parser.onload = function() {onload(this.contentWindow.document)}
      parser.contentWindow.location.href = src;
    }
    
    getDOM("somepage.html", function(doc) {
      alert("found: " + doc.getElementsByTagName("*").length);
    });
    this is the basic concept, g'luck


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •