Saturday 15 March 2014

XML and DataSet Objects

This article will definitely examine DataSet objects and in what ways XML is employed when working with DataSets. Let’s begin with looking at precisely what a DataSet is.

A DataSet is essentially an in-memory depiction of data, because the data itself can be kept to memory, it may be adjusted also it can be written back to the data source. Additionally it may comprise one or more DataTable objects.
The DataTable objects themselves could have rows and columns, called DataRows and DataColumns or perhaps a primary key, foreign key, and constraint and additionally relation information concerning the data in the DataTable objects.

The DataTable object symbolizes every table inside of a DataSet; and as a result the DataColumn object every single column within a DataTable and the DataRow object every row within the DataTable.

It is additionally important to consider that the DataSet would not validate the XML data against the schema; it simply uses it to infer the structure needed for the tables in the DataSet. The System.Data.DataSet class is provided to support DataSet in .NET.


What’s the DataSet Class in .Net?

The DataSet class in .NET is a fairly handy .Net aspect that allows you to build applications and store data in an XML file instead of having to hold and recover it from a database.

This can be done thanks to the considerable XML support showcased in the DataSet class for reading and writing data as XML, this can include the following techniques which I will explain in greater detail, GetXml Method, GetXmlSchema Method, InferXmlSchema Method, WriteXml Method, WriteXmlSchema Method, ReadXml Method, ReadXmlSchema Method.

So let’s examine each one of these approaches in a little more depth, I will show you the most suitable syntax as well.


The GetXml Method

This approach returns a string containing an XML representation of the actual data which is saved in the DataSet, the format is public string GetXml();


The GetXmlSchema Method

This method returns the schema for an XML expression of the information saved in the DataSet, it delivers the XML as a string so its a lot more verbose than the WriteXmlSchema approach to write XML to a file. The syntax is public string GetXmlSchema();

InferXmlSchema Method

This procedure can be applied XML schema to the DataSet by taking an XML document provided in a TextReader, XmlReader, Stream object or a particular hard disk drive file. The syntax is;

public void InferXmlSchema(string,string[]);
public void InferXmlSchema(TextReader,string[]);
public void InferXmlSchema(Stream,Stream[]);
public void InferXmlSchema(XmlReader,string[]);


WriteXml Method

This approach writes the XML illustration of the data in the DataSet object to a TextWriter object, an XmlWriter object, a Stream object or instantly to a specified disk file. The syntax is;

public void WriteXml(string);
public void WriteXml(TextWriter);
public void WriteXml(Stream);
public void WriteXml(XmlWriter);

WriteXmlSchema Method

This process creates the XML schema of the DataSet to a TextWriter object, an XmlWriter object, a Stream object or right to a specified hard disk drive file. The syntax is;

public void WriteXmlSchema(string);
public void WriteXmlSchema(TextWriter);
public void WriteXmlSchema(Stream);
public void WriteXmlSchema(XmlWriter);


ReadXml Method

This method scans the XML data (including a schema when present) into the DataSet from a TextReader, XmlReader, Stream object or straight to a specific hard drive file. The syntax is;

public void ReadXml(string);
public void ReadXml(TextReader);
public void ReadXml(Stream);
public void ReadXml(XmlReader);


ReadXmlSchema Method

This technique deciphers the XML schema explaining the contents of the DataSet to a TextReader, XmlReader, and Stream object or right to a specified hard disk drive file. The syntax is;

public void ReadXmlSchema(string);
public void ReadXmlSchema(TextReader);
public void ReadXmlSchema(Stream);
public void ReadXmlSchema(XmlReader);

Make sure that you bear mind that the preceding methods with DataSet will be more designed for working with small amounts of data a result of quantity of memory that is required, working copious amounts of information this may soon engulf just about any large software.