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

M

Mike

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
 
T

Thomas 'PointedEars' Lahn

Mike said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top