Anyone know of a small tag-based parser for parsing a text string in javascript?

Discussion in 'Javascript' started by Mike, Aug 20, 2004.

  1. Mike

    Mike Guest

    Hello, I have a string that will contain a table like this:
    <tr><td>column1data</td><td>column2data</td></tr>

    I want to use javascript to extract the data for a given row and
    column. I'm guessing the easiest would be to find a tag-based parser.
    Anyone know of one?

    BTW I checked out the xml parsers in javascript and I am looking for
    something simpler or at least easier to use.

    Thanks,
    Mike
     
    Mike, Aug 20, 2004
    #1
    1. Advertising

  2. Mike wrote:

    > Hello, I have a string that will contain a table like this:
    > <tr><td>column1data</td><td>column2data</td></tr>


    This is not a table, it is merely a table row.

    > I want to use javascript to extract the data for a given row and
    > column. I'm guessing the easiest would be to find a tag-based parser.


    The easiest way would be to access the DOM tree. Consider this table:

    <table id="foobar">
    <tr>
    <td>row1column1data</td>
    <td>row1column2data</td>
    </tr>

    <tr>
    <td>row2column1data</td>
    <td>row2column2data</td>
    </tr>
    </table>

    The data of the second column of the second row, if only a text node,
    can be accessed (in a DOM implementing the W3C-DOM Level 2 HTML) with

    var t;
    if ((t = typeof document.getElementById) == "function"
    || (t == "object" && document.getElementById))
    {
    var o = document.getElementById("foobar");
    if (o)
    {
    ... o.rows[1].cells[1].firstChild.nodeValue ...
    }
    }

    > Anyone know of one?


    I am currently hacking on a general parser prototype for my JSdoc that could
    probably be extended to handle markup languages, but it is not even alpha.
    Build one yourself, ...

    > BTW I checked out the xml parsers in javascript


    There are no XML parsers in J(ava)Script. You are confusing language(s) and
    DOM(s).

    > and I am looking for something simpler or at least easier to use.


    .... but I doubt that writing it would be simpler. I also wonder what you
    find hard to use in the available parsers.


    PointedEars
    --
    "I'm running M4.51 and..."
    -- Desperate Communicator user seeking help on moz.general
     
    Thomas 'PointedEars' Lahn, Aug 21, 2004
    #2
    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. nileppez
    Replies:
    0
    Views:
    404
    nileppez
    Aug 18, 2003
  2. shruds
    Replies:
    1
    Views:
    870
    John C. Bollinger
    Jan 27, 2006
  3. mkppk
    Replies:
    4
    Views:
    719
    mkppk
    Mar 25, 2007
  4. Simon Egginton

    LOOK! i just want to know does anyone know...

    Simon Egginton, Jul 26, 2004, in forum: Javascript
    Replies:
    3
    Views:
    183
    Dr John Stockton
    Jul 26, 2004
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    253
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page