Sample code for 30+ languages & platforms
SQL Server

Convert MIME to XML

See more MIME Examples

Demonstrates the Chilkat Mime.GetXml method, which converts the MIME tree to Chilkat's XML representation and returns it as a string. It takes no arguments. Header names become element names, structured header parameters become attributes, and duplicate headers become repeated elements.

Tip: Code to parse the returned XML can be generated at Chilkat Tools.

Background: Turning a MIME tree into XML exposes its structure in a form that ordinary XML tools can query and transform — useful for inspection, debugging, or feeding a message into an XML-based pipeline. It is the inverse of LoadXml, so a message can be round-tripped through XML. For a quick human-readable outline rather than a full representation, see GetStructure.

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
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  Demonstrates the Mime.GetXml method, which converts the MIME tree to Chilkat's XML
    --  representation and returns it as a string.  It takes no arguments.

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

    EXEC sp_OAMethod @mime, 'LoadMimeFile', @success OUT, 'qa_data/message.eml'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        RETURN
      END

    --  Header names become XML element names and structured header parameters become XML attributes.
    DECLARE @xml nvarchar(4000)
    EXEC sp_OAMethod @mime, 'GetXml', @xml OUT
    EXEC sp_OAGetProperty @mime, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        RETURN
      END

    PRINT @xml

    EXEC @hr = sp_OADestroy @mime


END
GO