SQL Server
SQL Server
Set a MIME Body from XML
See more MIME Examples
Demonstrates the Chilkat Mime.SetBodyFromXml method, which sets the body as XML, changes the media type to text/xml, and selects an appropriate transfer encoding. The only argument is the XML text.
Background: This produces an XML-typed part, common in machine-to-machine messaging — SOAP, AS2/EDI payloads, structured data attachments. Marking the content
text/xml lets the receiver route and parse it correctly, and Chilkat picks a transfer encoding that preserves the XML across the transport.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the Mime.SetBodyFromXml method, which sets the body as XML and changes the media
-- type to text/xml. The only argument is the XML text.
DECLARE @mime int
EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @xml nvarchar(4000)
SELECT @xml = '<note><to>Bob</to><from>Alice</from><body>Hello</body></note>'
EXEC sp_OAMethod @mime, 'SetBodyFromXml', @success OUT, @xml
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mime
RETURN
END
EXEC sp_OAGetProperty @mime, 'ContentType', @sTmp0 OUT
PRINT 'Content-Type: ' + @sTmp0
EXEC @hr = sp_OADestroy @mime
END
GO