Sample code for 30+ languages & platforms
SQL Server

Load XML from Local FilePath

Demonstrates how to load XML from a local XML file.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    DECLARE @xml int
    EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Pass either an absolute file path, or a file path relative from the current working directory of the caller.
    EXEC sp_OAMethod @xml, 'LoadXmlFile', @success OUT, 'qa_data/hamlet.xml'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @xml, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @xml
        RETURN
      END


    PRINT 'Success.'

    EXEC @hr = sp_OADestroy @xml


END
GO