Parsing DOM with Javascript

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

    Parsing DOM with Javascript

    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

  • pipe

    #2
    Re: Parsing DOM with Javascript

    >My problem is that i need an algorithm parse parse HTML.[color=blue]
    >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 ?[/color]

    gee, i dont know, can you?
    [color=blue]
    >Thanks[/color]

    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...

    Comment

    • alu

      #3
      Re: Parsing DOM with Javascript


      "pipe" <auditor400@gma il.com> wrote in message
      news:1129328453 .223636.69140@g 47g2000cwa.goog legroups.com...[color=blue][color=green]
      > >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 ?[/color]
      >
      > gee, i dont know, can you?
      >[color=green]
      > >Thanks[/color]
      >
      > 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...[/color]


      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(HTMLc ontent) {
      // split at <
      var re = "<"
      arrayOfTags = HTMLcontent.spl it(re)
      // restore split separator

      for (var i = 1; i < arrayOfTags.len gth; i++) {
      arrayOfTags[i] = "<" + arrayOfTags[i]
      }
      }

      function outPut(n) {
      alert(arrayOfTa gs[n])
      }

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

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



      -alu


      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Parsing DOM with Javascript

        djdave wrote:
        [color=blue]
        > 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 ?[/color]

        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.c om/work/webdeveloper/documentation/features/forms/>


        HTH

        PointedEars

        Comment

        Working...