XPath Query not working

I try to use the XPath node, but without success. My query works with every other XPath Tester I could find, but not in Knime. What am I doing wrong?

Example document:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="UTF-8">
        </meta>
    </head>
    <body>
        <div class="default-style">
			<table align="" border="0" cellpadding="0" cellspacing="0" class="m_-6430099549931739827width-100" style="line-height: 1em; margin: 0.5em auto;">
				<tbody>
					<tr>
						<td align="" bgcolor="" data-darkreader-inline-border-bottom="" data-darkreader-inline-border-top="" style="border-bottom: 1px solid #aaaaaa; padding: 0.4em 1em; border-top: 1px solid #555555;" valign="">TEXT <a href="https://example.com">https://example.com</a> text.</td>
					</tr>
					<tr class="m_-6430099549931739827align-top">
						<td class="m_-6430099549931739827text-element-label" data-darkreader-inline-border-bottom="" data-darkreader-inline-border-top="" style="border-bottom: 1px solid #aaaaaa; padding: 0.4em 1em; border-top: 1px solid #555555;">Name</td>
						<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-top="" style="border-bottom: 1px solid #aaaaaa; padding: 0.4em 1em; border-top: 1px solid #555555;">Special Name</td>
					</tr>
				</tbody>
			</table>
        </div>
    </body>
</html>

I want to have the “Special Name”. My query is:

//td[normalize-space(.) = 'Name']/following::td[1]/text()

Here is a simple flow where I try this
grafik

XPath Test.knwf (8.8 KB)

What exactly is your desired output?

Have you tried using the configuration in the XPath node to design the query? Just click on the element you want and select “Add XPath”.

image

1 Like

I am searching for a td which contains “Name” and then I want the content of the next td.
There might me multiple results, ie, multiple occurrences of td Name followed by another td

Your result is fine for this simple example. The real data is more complicated and requires the logic from above.