HtmlNodes
Retrieves HTML Nodes via XPath query and returns a table
- Free Function
- SQL Server Compatibility: 2008, 2012, 2014, 2016, 2017
SELECT *
FROM SQLHTTP.net.HtmlNode ( @Html, @Xpath )
Name | Type | Description |
---|---|---|
@Html | nvarchar(MAX) | String containing HTML |
@Xpath | nvachar(MAX) | An Xpath query |
Column name | Data type | Description |
---|---|---|
RowID | int | Node Index |
HtmlNode | nvarchar(MAX) | Node Content |
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 |
DECLARE @Html nvarchar(MAX) DECLARE @Xpath nvarchar(MAX) SET @Html = N' <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' SELECT RowID, LEFT(REPLACE(HtmlNode, CHAR(13) + CHAR(10), ''), 20) + '...' AS PartialHtmlNode FROM SQLHTTP.net.HtmlNodes(@Html, @Xpath) |
1 2 3 4 5 6 7 8 9 |
RowID PartialHtmlNode ----------- ------------------------------------------------ 1 <tr> <th>Year</th>... 2 <tr> <td>2017</td>... 3 <tr> <td>2018</td>... 4 <tr> <td>2019</td>... 5 <tr> <td>2020</td>... |