XPath to analyze HTML table

A

Achim Domma

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
 
D

Dimitre Novatchev

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

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top