5,401,186 members and growing! (16,944 online)
Email Password   helpLost your password?
Database » Database » General     Intermediate

XmlClient Managed Provider

By Shawn Wildermuth

A Class Library that holds a Managed Provider to retreive Load DataSets from Xml sources.
C#, Windows, .NET 1.0, .NETVisual Studio, VS.NET2002, DBA, Dev

Posted: 16 Apr 2002
Updated: 16 Apr 2002
Views: 53,286
Bookmarked: 13 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 1.91 Rating: 2.11 out of 5
3 votes, 75.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
1 vote, 25.0%
5

Introduction

This is my first attempt at writing a Managed Provider. The idea behind it was to allow users of the Managed Provider to be able to fill DataSets from XML in a homogeneous way. This way you could mix XML and database data together without having to know exactly which is from which.

Usage Notes

  • The Connection string for the XmlConnection class takes a URL or File path to an XML file.
  • The XmlCommand class takes an optional XPath expression to decide which subset of the XML file to include in the DataSet.

Example

    // call using: TestXml(@"c:\test.xml", "descendant::server[name='Kay']", 

    //                      "  ", "File Path with XPath Expression");


    static void TestXml(string URL, string XPath, string indent, string Title)
    {
      Console.WriteLine("Testing {0} \nwith XML Source: {1}", Title, URL);
      XmlDataAdapter da = new XmlDataAdapter(XPath, new XmlConnection(URL));

      da.SelectCommand.Connection.Open();
      DataSet ds = new DataSet();
      
      // Test Filling in with all data

      int rowsAffected = da.Fill(ds);
      Console.WriteLine(indent + "Filled DataSet with {0} rows", rowsAffected);
      string xml = ds.GetXml();

      // Test Filling with Schema only

      DataTable[] aTables = da.FillSchema(ds, SchemaType.Source);
      Console.WriteLine(indent + "Filled DataSet with {0} tables of Schema only", 
                        aTables.GetLength(0));

      // Show XML if XPath is used

      if (XPath != "/") Console.WriteLine(indent + "XPath Results: \n{0}", xml);
    }

Caveats

  • The DataReader was never implemented.
  • This Managed Provider is read-only. If you need to write with it, please contact me as I might be able to get something working.
  • When using an XPath expression in the XmlCommand class, only the first Match is loaded into the DataSet.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Shawn Wildermuth



Location: United States United States

Other popular Database articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 4 of 4 (Total in Forum: 4) (Refresh)FirstPrevNext
Subject  Author Date 
Generallooking forward to more on this...susstim mackey15:11 1 Nov '02  
GeneralWhat is the point of this article?memberpbible6:43 14 Jul '02  
GeneralRe: What is the point of this article?memberShawn Wildermuth9:16 14 Jul '02  
GeneralRe: What is the point of this article?memberAKourkoumelis10:01 8 Mar '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 16 Apr 2002
Editor: Chris Maunder
Copyright 2002 by Shawn Wildermuth
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project