XML
  Home arrow XML arrow Page 4 - Extracting XML content from an XML file fr...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Extracting XML content from an XML file from within SQL Server 2000 using Managed Code
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2005-11-29

    Table of Contents:
  • Extracting XML content from an XML file from within SQL Server 2000 using Managed Code
  • Developing the .NET component
  • Deploying the .NET component
  • Testing the .NET component from within SQL Server 2000
  • Creating a stored function to call the .NET component and testing it

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Extracting XML content from an XML file from within SQL Server 2000 using Managed Code - Testing the .NET component from within SQL Server 2000


    (Page 4 of 5 )

    After completing all of the above steps, we need to test the component.  To test the component, the first issue is that we need to create an XML file in any path.  As this is a demonstration, I created a simple file (“Sample.xml”) in my root C drive.  The content within that “Sample.xml” file would be as follows:

    <?xml version="1.0"?>

    <ROWSET>
     <ROW>
      <EMPNO>1001</EMPNO>
      <ENAME>aaaa</ENAME>
      <SAL>1300</SAL>
      <DEPTNO>10</DEPTNO>
     </ROW>
     <ROW>
      <EMPNO>1002</EMPNO>
      <ENAME>bbbb</ENAME>
      <SAL>3000</SAL>
      <DEPTNO>20</DEPTNO>
     </ROW>
    </ROWSET>

    After saving the above XML, open up your query analyzer and type the following Transact-SQL code, to test the component:

    DECLARE  @ExecutionResult INT, @errorSource VARCHAR(100), @errorDescription VARCHAR(100), @result VARCHAR(800),@hnd INT
     
    EXEC @ExecutionResult = sp_OACreate 'Utility.CUtility', @hnd OUTPUT
    IF (@ExecutionResult <> 0)
    BEGIN
          EXEC sp_OAGetErrorInfo @hnd, @errorSource OUTPUT, @errorDescription OUTPUT
          SELECT @errorSource, @errorDescription
    END
     
    EXEC @ExecutionResult = sp_OAMethod @hnd, 'getXMLContent', @result OUTPUT, 'c:\sample.xml'
    IF (@ExecutionResult <> 0)
    BEGIN
          EXEC sp_OAGetErrorInfo @hnd, @errorSource OUTPUT, @errorDescription OUTPUT
          SELECT @errorSource, @errorDescription
    END
     
    EXEC @ExecutionResult = sp_OADestroy @hnd
    IF (@ExecutionResult <> 0)
    BEGIN
          EXEC sp_OAGetErrorInfo @hnd, @errorSource OUTPUT, @errorDescription OUTPUT
     
          SELECT @errorSource, @errorDescription
    END
     
    SELECT @result

    Just press F5 to execute the script and it should return to you the content available in the “c:\sample.xml” file.  It is not necessary to handle the errors as above, but it is a good practice to have it included.

    More XML Articles
    More By Jagadish Chaterjee


       · Hello, did you ever work with Managed code with SQL Server 2000 (together with...
     

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT