|
-
May 26th, 2012, 09:43 PM
#1
nested HTML table and xpath: matching level one child node
hi, this is a nested HTML table. Using Xpath .//table//tr we can retrieve all table rows. That's what double forward slashes does for you (matches not only level one beaneath current node but also any sub level deeper in the hierarchy).
What I want to achieve is to be able to retrieve first-level table rows only but WITHOUT hardcoding path using single forward slash:
.//table/tr
As we can, possibly, have <tbody> tag sitting beneath <table> tag but about <tr>, in which case above xpath will miss!
(But using double forward slashes on tr will capture second level tr's which I want to exclude)
Many thanks
Code:
<html>
<head>Sample page</head>
<body>
<table>
<tr>
<td>
<table>
<tr>
<td>Name</td>
<td>John Doe</td>
<tr>
<tr>
<td>Tel</td>
<td>416-987-1234</td>
<tr>
</table>
</td>
<td>
<table>
<tr>
<td>EmpID</td>
<td>12345</td>
<tr>
<tr>
<td>Salary</td>
<td>75000</td>
<tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|