Home arrow XML arrow Page 2 - Extracting XML content from an XML file from within SQL Server 2000 using Managed Code
XML

Extracting XML content from an XML file from within SQL Server 2000 using Managed Code


This article explains how to develop a .NET based component, which can extract XML content from an XML file and return the same to SQL Server 2000 with the help of T-SQL (Transact-SQL).

Author Info:
By: Jagadish Chaterjee
Rating: 5 stars5 stars5 stars5 stars5 stars / 6
November 29, 2005
TABLE OF CONTENTS:
  1. · Extracting XML content from an XML file from within SQL Server 2000 using Managed Code
  2. · Developing the .NET component
  3. · Deploying the .NET component
  4. · Testing the .NET component from within SQL Server 2000
  5. · Creating a stored function to call the .NET component and testing it

print this article
SEARCH DEVARTICLES

Extracting XML content from an XML file from within SQL Server 2000 using Managed Code - Developing the .NET component
(Page 2 of 5 )

I create a simple .NET component with only one method, which accepts “FilePath” (or XML file name along with its path information) as parameter and returns the entire XML content in the form of “string”.

You can start opening your Visual Studio and proceed through the following steps:

  • Go to File -> New -> Project.
  • Select “Class Library” as Project Template and specify the “Name” of the project as “Utility”.  You will be presented with a default class “Class1”
  • Within the “Solution Explorer”, right click on “Class1” and delete it.
  • Again within the “Solution Explorer”, right click on the project, go to Add -> Add Class.
  • Give the name of the class as “IUtility” and modify the code as follows:

 Public Interface IUility

    Function getXMLContent(ByVal FilePath As String) As String
End Interface
  • Again within the “Solution Explorer”, right click on the project, go to Add -> Add Class.
  • Give the name of the class as “CUtility” and modify the code as follows:

Imports System.IO

Public Class CUtility
    Implements IUility
 
    Public Function getXMLContent(ByVal FilePath As String) As String Implements IUility.getXMLContent
        Try
            Dim sr As New StreamReader(FilePath)
            Dim content As String = sr.ReadToEnd()
            Return content
            sr.Close()
        Catch ex As Exception
            Throw New Exception("Could not read XML File. Error: " & ex.Message)
        End Try
    End Function
End Class
  • Again within the “Solution Explorer”, double click on “AssemblyInfo.vb” and add the following line at the bottom:

<Assembly: AssemblyKeyFile("..\..\Utility.snk")>

  • Go to Start -> Programs -> Microsoft Visual Studio.NET 2003 -> Visual Studio.NET tools -> Visual Studio.NET 2003 Command Prompt.
  • Go to the path of your project folder (which is “Utility”), using the Command Prompt.
  • Type the following command to provide a strong name to the component.  The strong name key pair is necessary for registering the component with GAC cache.

Sn –k Utility.snk

  • Now build your solution by pressing Ctrl+Shift+B.  It should complete successfully.  If you receive any errors, double-check the path of “Utility.snk”.  It should be available in the same project folder (and not in “bin” or any other sub folder).


blog comments powered by Disqus
XML ARTICLES

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials