XmlClient Managed Provider






3.50/5 (5 votes)
Apr 17, 2002

73227

1572
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 DataSet
s 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 optionalXPath
expression to decide which subset of the XML file to include in theDataSet
.
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 theXmlCommand
class, only the first Match is loaded into theDataSet
.