Data islands

Scripts often don't have the same level of data and logic separation as programs in "traditional" languages. And this is for a good reason: logic in scripts changes about as often as the data being processed (and if it's not true, "traditional" compiled programming language, with type validation etc, would be, arguably, a better choice).

So a scripting language needs a way to hardcode data into the script itself in text, XML, or CSV. Ideally, it should be as easy to use external files too. CSV support may be surprising if there is XML, but I often find CSV and text a lot easier to read and modify than XML because of reduced verbosity.

For example,

 

is a lot more readable than
 

Rowset

More often than not when writing scripts there is a need to deal with flat lists of objects, not object hierarchies. Could be lists of files, SQL tables and so on.

To represent this type of data, there is rowset action, which contains multiple rows in it. Representation may different, whatever is more convenient to the writer.

For example, XML using a special action to for every record, with attributes being values.

 

or "normal" XML using elements

 

or CSV using comma or other column separator

 

All these notations are equivalent. The final line prints the rowset nicely as a table:

 

Rowset may also be converted to a .NET DataTable using .ToDataTable() method.

By default columns are treated as text, but type may be explicitly specified. Also one rowset may be derived from another rowset with filtering and sorting. For example, the below prints total cost of cereal ( 2.49 * 9 = 21.41 ). For comparison, cost of meat is calculated using C# snippet with LINQ (this one requires .NET 3.0).

 

Xml document

There is also a basic support for XML data islands, to represent hierarchical structures.

With the following definition
 

The code below prints inner XML of paragraph par1
 

This prints the first bold text in par1:
 

The data can be also accessed from C# code, using the usual XML parsing tools from .NET 2.0:

 

Finally, if executed on machine with .NET3, LINQ for XML can be used:

 

Also, the data may be loaded from file instead of being specified directly:

 

There are many other possibilities, including conversions between XmlDoc/RowSet/.NET DataTable/text table/CSV format/XML etc.