Sample code for 30+ languages & platforms
SQL Server

XML GetChildWithAttr

See more XML Examples

Demonstrates how to get the content of a particular node with a particular attribute. For example, returns "Face up in the Rain" for the Name="Album" node.
 <Response Status="OK">
   <Item Name="ZoneID">0</Item>
   <Item Name="State">2</Item>
   <Item Name="FileKey">305718</Item>
   <Item Name="Artist">Michael Tomlinson</Item>
   <Item Name="Album">Face Up in the Rain</Item>
   <Item Name="Name">The Way We're Going</Item>
   <Item Name="Status">Playing</Item>
</Response> 

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
    -- 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

    EXEC sp_OAMethod @xml, 'LoadXmlFile', @success OUT, 'qa_data/resp.xml'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @xml, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @xml
        RETURN
      END

    DECLARE @xItem int
    EXEC sp_OAMethod @xml, 'GetChildWithAttr', @xItem OUT, 'Item', 'Name', 'Album'
    EXEC sp_OAGetProperty @xml, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN

        PRINT 'not found.'
        EXEC @hr = sp_OADestroy @xml
        RETURN
      END

    EXEC sp_OAGetProperty @xItem, 'Content', @sTmp0 OUT
    PRINT @sTmp0

    EXEC @hr = sp_OADestroy @xItem


    EXEC @hr = sp_OADestroy @xml


END
GO