Click here to Skip to main content
15,884,697 members
Articles / Programming Languages / C#
Article

XmlClient Managed Provider

Rate me:
Please Sign up or sign in to vote.
3.50/5 (5 votes)
16 Apr 2002 72.9K   1.6K   25   4
A Class Library that holds a Managed Provider to retreive Load DataSets from Xml sources.

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

C#
// 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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generallooking forward to more on this... Pin
tim mackey1-Nov-02 14:11
tim mackey1-Nov-02 14:11 
hi,
this is a fine idea that i would be very interested in seeing fully implemented. i don't know why they didn't include it in the .net framework already.

hope you get time to put more work into it. i would certainly use it.
thanks, tim.
QuestionWhat is the point of this article? Pin
pbible14-Jul-02 5:43
pbible14-Jul-02 5:43 
AnswerRe: What is the point of this article? Pin
Shawn Wildermuth14-Jul-02 8:16
Shawn Wildermuth14-Jul-02 8:16 
GeneralRe: What is the point of this article? Pin
AKourkoumelis8-Mar-04 9:01
AKourkoumelis8-Mar-04 9:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.