XPath to analyze HTML table

Discussion in 'XML' started by Achim Domma, Jul 29, 2003.

  1. Achim Domma

    Achim Domma Guest

    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
    Achim Domma, Jul 29, 2003
    #1
    1. Advertising

  2. "Achim Domma" <> wrote in message
    news:bg6pn2$c9l$02$-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
    Dimitre Novatchev, Jul 30, 2003
    #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. =?Utf-8?B?TmVtbw==?=
    Replies:
    0
    Views:
    347
    =?Utf-8?B?TmVtbw==?=
    Nov 30, 2005
  2. Matthias Roselieb

    Struts analyze Params

    Matthias Roselieb, Jul 21, 2003, in forum: Java
    Replies:
    0
    Views:
    338
    Matthias Roselieb
    Jul 21, 2003
  3. Nicola Trevisan

    Analyze an e-mail

    Nicola Trevisan, May 24, 2004, in forum: Java
    Replies:
    2
    Views:
    390
    Roedy Green
    May 24, 2004
  4. John Creighton

    Re: Newbie attempts to analyze diet

    John Creighton, Aug 20, 2004, in forum: Java
    Replies:
    1
    Views:
    350
  5. PHP
    Replies:
    8
    Views:
    472
Loading...

Share This Page