Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath to analyze HTML table

Reply
Thread Tools

XPath to analyze HTML table

 
 
Achim Domma
Guest
Posts: n/a
 
      07-29-2003
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


 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      07-30-2003

"Achim Domma" <(E-Mail Removed)> wrote in message
news:bg6pn2$c9l$02$(E-Mail Removed)-online.com...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
XPath: efficiency in xpath expressions Tjerk Wolterink XML 1 11-13-2004 06:03 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments