SQL Server Stored Procedure Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

SQL Server
Stored Procedure Examples

Quick Start
Encryption
File Access
IMAP
POP3
SMTP
Email Object
DKIM / DomainKey
FTP
HTML Conversion
HTTP
MHT
MIME
NTLM
RSA
Diffie-Hellman
DSA
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
String
Tar
Upload
XML
XMP
Zip

Amazon S3
Bz2
CSV
FileAccess
Byte Array
RSS
Atom
Self-Extractor

Building an XML Document

Demonstrates how to build the following XML document:

<accrep:AccidentReport>
  <accrep:VehicleSection>
    <accrep:Vehicle>
      <accrep:DriverOrPedestrian>D</accrep:DriverOrPedestrian>
      <accrep:Number>1</accrep:Number>
      <accrep:Name>
        <accrep:First>John</accrep:First>
        <accrep:Last>Doe</accrep:Last>
        <accrep:Middle>Robert</accrep:Middle>
      </accrep:Name>
      <accrep:Passengers>
        <accrep:Name>
          <accrep:First>John</accrep:First>
          <accrep:Last>Doe, Jr.</accrep:Last>
          <accrep:Middle>Robert</accrep:Middle>
        </accrep:Name>
      </accrep:Passengers>
      <accrep:Passengers>
	  <accrep:Name>
          <accrep:First>Sally</accrep:First>
          <accrep:Last>Doe</accrep:Last>
          <accrep:Middle>Crystal</accrep:Middle>
        </accrep:Name>
      </accrep:Passengers>
    </accrep:Vehicle>
    <accrep:Vehicle>
      <accrep:DriverOrPedestrian>D</accrep:DriverOrPedestrian>
      <accrep:Number>2</accrep:Number>
      <accrep:Name>
        <accrep:First>John</accrep:First>
        <accrep:Last>Public</accrep:Last>
        <accrep:Middle>Q</accrep:Middle>
      </accrep:Name>
      <accrep:Passengers>
        <accrep:Name>
          <accrep:First>Billy</accrep:First>
          <accrep:Last>Public</accrep:Last>
          <accrep:Middle>Bob</accrep:Middle>
        </accrep:Name>
      </accrep:Passengers>
      <accrep:Passengers>
	  <accrep:Name>
          <accrep:First>Kelly</accrep:First>
          <accrep:Last>Public</accrep:Last>
          <accrep:Middle>Emily</accrep:Middle>
        </accrep:Name>
      </accrep:Passengers>
    </accrep:Vehicle>
  </accrep:VehicleSection>
</accrep:AccidentReport>

Download Chilkat XML ActiveX

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @xml1 int
    EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml1 OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OASetProperty @xml1, 'Tag', 'accrep:AccidentReport'
    DECLARE @xml2 int

    EXEC sp_OAMethod @xml1, 'NewChild', @xml2 OUT, 'accrep:VehicleSection', ''
    DECLARE @xml3 int

    EXEC sp_OAMethod @xml2, 'NewChild', @xml3 OUT, 'accrep:Vehicle', ''
    EXEC sp_OAMethod @xml3, 'NewChild2', NULL, 'accrep:DriverOrPedestrian', 'D'
    EXEC sp_OAMethod @xml3, 'NewChild2', NULL, 'accrep:Number', '1'
    DECLARE @xml6 int

    EXEC sp_OAMethod @xml3, 'NewChild', @xml6 OUT, 'accrep:Name', ''
    EXEC sp_OAMethod @xml6, 'NewChild2', NULL, 'accrep:First', 'John'
    EXEC sp_OAMethod @xml6, 'NewChild2', NULL, 'accrep:Last', 'Doe'
    EXEC sp_OAMethod @xml6, 'NewChild2', NULL, 'accrep:Middle', 'Robert'

    DECLARE @xml10 int

    EXEC sp_OAMethod @xml3, 'NewChild', @xml10 OUT, 'accrep:Passengers', ''
    DECLARE @xml11 int

    EXEC sp_OAMethod @xml10, 'NewChild', @xml11 OUT, 'accrep:Name', ''
    EXEC sp_OAMethod @xml11, 'NewChild2', NULL, 'accrep:First', 'John'
    EXEC sp_OAMethod @xml11, 'NewChild2', NULL, 'accrep:Last', 'Doe, Jr.'
    EXEC sp_OAMethod @xml11, 'NewChild2', NULL, 'accrep:Middle', 'Robert'

    DECLARE @xml15 int

    EXEC sp_OAMethod @xml3, 'NewChild', @xml15 OUT, 'accrep:Passengers', ''
    DECLARE @xml16 int

    EXEC sp_OAMethod @xml15, 'NewChild', @xml16 OUT, 'accrep:Name', ''
    EXEC sp_OAMethod @xml16, 'NewChild2', NULL, 'accrep:First', 'Sally'
    EXEC sp_OAMethod @xml16, 'NewChild2', NULL, 'accrep:Last', 'Doe'
    EXEC sp_OAMethod @xml16, 'NewChild2', NULL, 'accrep:Middle', 'Crystal'

    DECLARE @xml20 int

    EXEC sp_OAMethod @xml2, 'NewChild', @xml20 OUT, 'accrep:Vehicle', ''
    EXEC sp_OAMethod @xml20, 'NewChild2', NULL, 'accrep:DriverOrPedestrian', 'D'
    EXEC sp_OAMethod @xml20, 'NewChild2', NULL, 'accrep:Number', '2'
    DECLARE @xml23 int

    EXEC sp_OAMethod @xml20, 'NewChild', @xml23 OUT, 'accrep:Name', ''
    EXEC sp_OAMethod @xml23, 'NewChild2', NULL, 'accrep:First', 'John'
    EXEC sp_OAMethod @xml23, 'NewChild2', NULL, 'accrep:Last', 'Public'
    EXEC sp_OAMethod @xml23, 'NewChild2', NULL, 'accrep:Middle', 'Q'

    DECLARE @xml27 int

    EXEC sp_OAMethod @xml20, 'NewChild', @xml27 OUT, 'accrep:Passengers', ''
    DECLARE @xml28 int

    EXEC sp_OAMethod @xml27, 'NewChild', @xml28 OUT, 'accrep:Name', ''
    EXEC sp_OAMethod @xml28, 'NewChild2', NULL, 'accrep:First', 'Billy'
    EXEC sp_OAMethod @xml28, 'NewChild2', NULL, 'accrep:Last', 'Public'
    EXEC sp_OAMethod @xml28, 'NewChild2', NULL, 'accrep:Middle', 'Bob'

    DECLARE @xml32 int

    EXEC sp_OAMethod @xml20, 'NewChild', @xml32 OUT, 'accrep:Passengers', ''
    DECLARE @xml33 int

    EXEC sp_OAMethod @xml32, 'NewChild', @xml33 OUT, 'accrep:Name', ''
    EXEC sp_OAMethod @xml33, 'NewChild2', NULL, 'accrep:First', 'Kelly'
    EXEC sp_OAMethod @xml33, 'NewChild2', NULL, 'accrep:Last', 'Public'
    EXEC sp_OAMethod @xml33, 'NewChild2', NULL, 'accrep:Middle', 'Emily'

    --  Display the XML:
    EXEC sp_OAMethod @xml1, 'GetXml', @sTmp0 OUT
    PRINT @sTmp0


END
GO

 

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.