HtmlTable_To_Xml
Converts an HTML Table to XML
- Free Function
- SQL Server Compatibility: 2008, 2012, 2014, 2016, 2017
SELECT SQLHTTP.net.HtmlTable_To_Xml ( @Html, @FirstRowContainsHeaderNames )
Name | Type | Description |
---|---|---|
@Html | nvarchar(MAX) | An nvarchar(MAX) HTML string |
FirstRowContainsHeaderNames | bit | 1 = The first <tr> tag will contain <th> tags. 0 = The first <tr> tag will NOT contain <th> tags, unless the HTML Table contains a <thead> tag |
xml
and tags are not included in the resulting XML
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 45 46 47 48 49 50 51 52 53 54 55 56 |
DECLARE @Html nvarchar(MAX) DECLARE @FirstRowContainsHeaderNames bit SET @Html = N' <html> <head> <title>Daylight saving time</title> </head> <body> <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> <table> <tr> <td> This second table is included here to demonstrate <br /> that only the first table is referenced! </td> <tr> </table> </body> </html>' SET @FirstRowContainsHeaderNames = 0 --Ignored in this example as the HTML table contains a thead tag SELECT SQLHTTP.net.HTMLTable_To_Xml(@Html, @FirstRowContainsHeaderNames) |
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 |
<table> <tr> <th>Year</th> <th>Start date</th> <th>Ending date</th> </tr> <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> </table> |