XPath to analyze HTML table

Achim Domma

Usenet Archive
Joined
Sep 17, 2002
Messages
57
Reaction score
0
Hi,

I have some HTML code, converted to XML and want to get the content of special table cells. The XML looks like this:

....
<tr>
<td width="200">
<font class="content">Project ID</font>
</td>
<td width="200">
<font class="content">12345</font>
</td>
</tr>
....

I want to get '12345' and tried it with an XPath expression like this:

'//font[starts-with(text,"Project")]/parent/parent/td[2]/font/text

It does not work, but I don't understand why!? Can anybody help?

regards,
Achim
 

Dimitre Novatchev

Usenet Archive
Joined
Nov 7, 2000
Messages
737
Reaction score
0
Achim Domma said:
Hi,

I have some HTML code, converted to XML and want to get the content of special table cells. The XML looks like this:

...
<tr>
<td width="200">
<font class="content">Project ID</font>
</td>
<td width="200">
<font class="content">12345</font>
</td>
</tr>
...

I want to get '12345' and tried it with an XPath expression like this:

'//font[starts-with(text,"Project")]/parent/parent/td[2]/font/text

It does not work, but I don't understand why!? Can anybody help?

The reason is that there are no "parent" elements defined in html.

Probably you meant parent::* or simply ".."

I would re-write your XPath expression to something like the following:

//tr[td/font[starts-with(., 'Project')]]/td[2]/font/text[1]

Another recommendation is to download the XPath Visualizer and play with it to learn XPath the fun way.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 

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

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,224
Members
248,132
Latest member
henrywalsh

Latest Threads

Top