(SQL Server) Convert HTML to plain-text
Demonstrates how to convert HTML to plain-text.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @h2t int
-- Use "Chilkat_9_5_0.HtmlToText" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.HtmlToText', @h2t OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Set the HTML:
DECLARE @html nvarchar(4000)
SELECT @html = '<html><body><p>This is a test.</p><blockquote>Here is text within a blockquote</blockquote></body></html>'
DECLARE @plainText nvarchar(4000)
EXEC sp_OAMethod @h2t, 'ToText', @plainText OUT, @html
PRINT @plainText
-- The output looks like this:
-- This is a test.
--
-- Here is text within a blockquote
EXEC @hr = sp_OADestroy @h2t
END
GO
|