HtmlNode
Retrieves an HTML Node via XPath query
- Free Function
- SQL Server Compatibility: 2008, 2012, 2014, 2016, 2017
SELECT SQLHTTP.net.HTMLNode ( @Html, @Xpath, @Index )
Name | Type | Description |
---|---|---|
@Html | nvarchar(MAX) | String containing HTML |
@Xpath | nvarchar(MAX) | An Xpath query |
@Index | bigint | Index position of the XPath query result |
nvarchar(MAX)
This example demonstrates retrieving the first <tr> tag from an HTML Table:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
DECLARE @HTML nvarchar(MAX) DECLARE @Xpath nvarchar(MAX) DECLARE @Index bigint SET @HTML = ' <table align="center"> <thead> <tr> <th>Year</th> <th>Start date</th> <th>Ending date</th> </tr> </thead> <tbody> <tr> <td>2017</td> <td>March 12</td> <td>November 5</td> </tr> <tr> <td>2018</td> <td>March 11</td> <td>November 4</td> </tr> <tr> <td>2019</td> <td>March 10</td> <td>November 3</td> </tr> <tr> <td>2020</td> <td>March 8</td> <td>November 1</td> </tr> </tbody> </table>' SET @Xpath = N'//tr' SET @Index = 1 SELECT SQLHTTP.net.HTMLNode(@Html, @Xpath, @Index) |
1 2 3 4 5 6 7 8 |
------------------------------------- <tr> <th>Year</th> <th>Start date</th> <th>Ending date</th> </tr> |