Skip to content

How XML is initially interpreted

RDunkley edited this page Jul 4, 2014 · 1 revision

Introduction

The XML-To-Data-Class tool initially interprets the data found in an XML file into data types and classes. The user is then able to modify the interpreted data to make any necessary corrections prior to generating the code. This wiki page explains how the tool initially interprets the data to give the user a better understanding of how the default data types are obtained.

XML Overview

XML can be divided up into two main components: elements and attributes. A description of the two elements can be found on W3Schools. The XML-To-Data-Class tool generates classes for each unique element tag and adds properties in those classes to represent attributes in the element. The text inside the element opening and closing tags is also added as an attribute. Child CDATA elements are also added as a property in the parent element. For example, the following XML:

<house>
  <room sqft="1000">
    <table type="wood" width="4" depth="4" height="3"/>
    <dresser color="blue" num_drawers="5"/>
  </room>
</house>

Creates four data classes (House, Room, Table, and Dresser) named in Capital Case. The House class would contain a property that would be an array of Room objects. The Room class would contain a property that would be an array of Table objects and a property that would be an array of Dresser objects. The attributes would also be assigned to properties. A simple example of the generated classes would be similar to:

public class House
{
    public Room[] ChildRoomArray { get; private set; }
}
public class Room
{
    public int Sqft { get; private set; }
    public Table[] ChildTableArray { get; private set; }
    public Dresser[] ChildDresserArray { get; private set; }
}
public class Table
{
    public string Type { get; private set; }
    public int Width { get; private set; }
    public int Depth { get; private set; }
    public int Height { get; private set; }
}
public class Dresser
{
    public string Color { get; private set; }
    public int NumDrawers { get; private set; }
}
Clone this wiki locally