BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
Schemas, xsd, xdr
XSD schemaLocation
Selecting Elements in Schemas
Specifying Namespaces
XSD targetNamespace
XSD Schemas
Convert XDR to XSD
Learn XSD Schemas .NET Tutorial
Conversion of genealogical files to XML with a DTD
AccessXML
Sorting by date without using a schema
Validating and enforcing a list of attribute values
Entity name support without DTDs
The Loss of Formatting When Adding a Schema
simple xml notepad
Schemas using DBMS_XMLQuery Package
Tips for Designing a DTD - Part 1 of 4
Tips for Designing a DTD- Part 2 of 4 : Semi-Structured Documents
Tips for Designing a DTD- Part 3 of 4 : Database Oriented Data
Tips for Designing a DTD- Part 4 of 4 : Object Oriented Data
Getting the value of an element with optional subelements
<< reBlogger
SEO >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :597

 

Strongly Typed .NET DataSet

We learned about two different approaches to access XML data: transforming each element in an XML document into a .NET object with the XmlSerializer or loading entire XML documents into an ADO.NET DataSet. We can access and manipulate the data in the DataSet through tables, rows and columns, just as if we were accessing a database. Chapter 8 also introduced us to typed DataSets that enforce a specific structure on the XML data they expose.

It is rather complex to create a typed DataSet class by hand. Fortunately the schema definition tool can create a typed DataSet from an XSD schema that describes the data structure. We simply need to let the tool know to produce a DataSet class rather than a class for the XmlSerializer when we specify a file with a .xsd extension by replacing the /d with the /d option. The following example creates a DataSet from the schema in listing C.2:

xsd.exe garage.xsd /d

Elements in the schema are modeled as tables; relationships between the elements are expressed as relationships between these tables as following code snippet shows:

8           Listing C.8 Types DataSet definition created by the XSD tool.

using System;

using System.Data;

using System.Xml;

using System.Runtime.Serialization;

[Serializable()]

[System.ComponentModel.DesignerCategoryAttribute("code")]

[System.Diagnostics.DebuggerStepThrough()]

[System.ComponentModel.ToolboxItem(true)]

public class NewDataSet : DataSet {             | #1

   

  private garageDataTable tablegarage;        | #2

  private carDataTable tablecar;              |

  private garageCarDataTable tablegarageCar;  |

  private DataRelation relationgarage_car;    |

   

  public NewDataSet() {

      this.InitClass();

      System.ComponentModel.CollectionChangeEventHandler

        schemaChangedHandler = new

          System.ComponentModel.CollectionChangeEventHandler(

            this.SchemaChanged);

      this.Tables.CollectionChanged += schemaChangedHandler;

      this.Relations.CollectionChanged += schemaChangedHandler;

  }

   

  protected NewDataSet(SerializationInfo info,

    StreamingContext context) {

    string strSchema = ((string)(info.GetValue("XmlSchema",

      typeof(string))));

    if ((strSchema != null)) {

      DataSet ds = new DataSet();

      ds.ReadXmlSchema(new XmlTextReader(

        new System.IO.StringReader(strSchema)));

      if ((ds.Tables["garage"] != null)) {

        this.Tables.Add(new garageDataTable(ds.Tables["garage"]));

      …(annotation) <#1 The schema id is used for the class name. The class derives from the DataSet class/ >

(annotation) <#1 Elements in the schema are represented as tables and relationships.>

The listing for the complete class would go on for the next fifteen or so pages, but I think you get the point: Creating a typed DataSet and all supporting classes is very complex. The XSD tool is the only viable option to create typed DataSet classes.

XSD Switches

We can mix the /l and /n options together with the /d option to select the programming language and the .NET namespace. The /e and /u option however, have no effect on the generated DataSet.


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

An immediate job opportunity as a B
Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C

View all Jobs (Add yours)
View all CV (Add yours)



answering service
online fax
swimming pool contractor
conference calling services
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP