Parsing DOM with Javascript

Discussion in 'Javascript' started by djdave, Oct 14, 2005.

  1. djdave

    djdave Guest

    My problem is that i need an algorithm parse parse HTML.
    For an HTML page, my script has to parse all tags to get all forms
    values, even if there is frame, iframe, ...
    How can i do such a script ?

    Thanks
     
    djdave, Oct 14, 2005
    #1
    1. Advertising

  2. djdave

    pipe Guest

    >My problem is that i need an algorithm parse parse HTML.
    >For an HTML page, my script has to parse all tags to get all forms
    >values, even if there is frame, iframe, ...
    >How can i do such a script ?


    gee, i dont know, can you?

    >Thanks


    iframes may give you problems, since sometimes, you can get the access
    denied msg,
    other than that, i would use the innerHTML, and then some old fashoned
    regexp work,
    but there are probably better ways...
     
    pipe, Oct 14, 2005
    #2
    1. Advertising

  3. djdave

    alu Guest

    "pipe" <> wrote in message
    news:...
    > >My problem is that i need an algorithm parse parse HTML.
    > >For an HTML page, my script has to parse all tags to get all forms
    > >values, even if there is frame, iframe, ...
    > >How can i do such a script ?

    >
    > gee, i dont know, can you?
    >
    > >Thanks

    >
    > iframes may give you problems, since sometimes, you can get the access
    > denied msg,
    > other than that, i would use the innerHTML, and then some old fashoned
    > regexp work,
    > but there are probably better ways...



    I was hoping someone in-the-know would respond to this request,
    as I'm interested in a solution myself.
    Your subject line is "parsing the DOM", while your post
    implies simply parsing HTML tags.
    If that's the case, I've done this before by simply placing each tag into
    an array element. This could be easily adapted to include iframes
    and frames, the content of which must be within the same domain.
    Very crude solution....

    // -------------------------------

    // array to hold all html tags
    arrayOfTags = new Array();
    // populate array
    function parseHTML(HTMLcontent) {
    // split at <
    var re = "<"
    arrayOfTags = HTMLcontent.split(re)
    // restore split separator

    for (var i = 1; i < arrayOfTags.length; i++) {
    arrayOfTags = "<" + arrayOfTags
    }
    }

    function outPut(n) {
    alert(arrayOfTags[n])
    }

    // -------------------------------------

    <div onclick="outPut(1)">click to see array element 1</div>



    -alu
     
    alu, Oct 15, 2005
    #3
  4. djdave wrote:

    > My problem is that i need an algorithm parse parse HTML.
    > For an HTML page, my script has to parse all tags to get all forms
    > values, even if there is frame, iframe, ...
    > How can i do such a script ?


    Iterate and recurse through the `frames' collection, access the `forms'
    collections of the respective `document' properties/objects and access
    their `elements' collections. Whatever you consider "form values", you
    may want to look for elements with specific `type' property/attribute
    values.

    However, there is already a bookmarklet for this, though I have not
    tested or analyzed if it works with frames:

    <http://www.squarefree.com/bookmarklets/forms.html>

    implemented in

    <http://chrispederick.com/work/webdeveloper/documentation/features/forms/>


    HTH

    PointedEars
     
    Thomas 'PointedEars' Lahn, Oct 18, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thorsten Meininger
    Replies:
    0
    Views:
    444
    Thorsten Meininger
    Jul 28, 2004
  2. Thorsten Meininger
    Replies:
    0
    Views:
    513
    Thorsten Meininger
    Jul 28, 2004
  3. mike
    Replies:
    1
    Views:
    1,154
    Martin Honnen
    Nov 20, 2004
  4. Replies:
    0
    Views:
    560
  5. Replies:
    1
    Views:
    107
    Martin Honnen
    Nov 9, 2006
Loading...

Share This Page