Home > 2010 Winter BTI420 > XML technologies for BTI420 students

XML technologies for BTI420 students

During your time in BTI420, you have worked with XML in your web forms (ASPX) markup, in Web.config and elsewhere. This post discusses the XML technologies that a second-year student should learn and know.


XML is an initialism for “extensible markup language”.

XML expresses and describes data. Its primary goal is to facilitate the description and transport of structured data between systems. XML enables the creation of expressive markup language syntax for a problem or application domain (hence the use of the word “extensible”).

The definition for XML that we introduced last week was:

XML is a text-based language-independent data interchange format.

Its roots are based on the decades-old SGML, Standard Generalized Markup Language. Although XML enables the creation of new “language syntaxes”, as noted above, some well-known XML implementations for BTI420 students include XHTML, as well as ASP.NET configuration components (e.g. Web.config), and ASP.NET DataSet schema.

While XML implementations are often intended to be human-readable (and understandable by people), XML is intended to be processed by software – read, write, change, transport, transform, etc.

The virtual textbook page has many links to articles that help you learn about XML technologies. I would suggest the following:

XML in 10 points (W3C)

XML (Wikipedia)

XML Tutorial (W3Schools)

XML Editor (in Visual Studio) (MSDN)

An Introduction to the XML Tools in Visual Studio 2005 (still valid ) (MSDN)

They do a good job of describing XML, so I won’t attempt to repeat their contents. As you are learning about XML, please open and examine a number of files from your web site / application, including:

  • any of your web forms, and look at the source/markup view
  • your Web.config file
  • your Web.sitemap file
  • any of your data access layer (DataSet schema), in code view


What you should have learned from the readings

There are a few key points that you should have learned from the readings. If the following points don’t resonate with you, go back to the readings.

  • XML must be well-formed
  • XML must be valid – schema (DTD or XSD) helps you determine the validity
  • XML can represent structured data that is hierarchical or table-oriented – it is quite flexible this way
  • you can use API’s that enable three different kinds of programmatic access – tree model, cursor-based, and stream-based
  • XML is baked into the .NET Framework

(And no, this isn’t a five-point summary of twenty pages of material. You really do need to go through the reference material. Don’t be lazy.)


Our objectives in learning about XML technologies

We have a few important objectives as we learn about XML technologies. They include:

> Learn about XML as a data payload format as used in web services

> Learn, at an introductory level, a few ways to read and write XML

> Learn how to create endpoints for current needs and future needs (e.g. the third-year project course, and some of your professional option courses)


Working hands-on with XML – schema and navigation

Schema defines valid XML. We will look at some familiar schema in a hands-on and introductory way to ensure that you get the concept.

In class, we’ll work with the XML editing tools in Visual Studio, and get you comfortable working with XML.

Before we do programmatic navigation, we will look at navigation using a browser. IE or Firefox enable navigation of well-formed XML documents.


XML processing options

There is an MSDN article titled “XML Processing Options” that provides an overview of the technologies Microsoft has for processing XML data. We will get an introduction to three of the technologies:

XmlDocument – implements the W3C DOM interfaces for reading and writing XML documents; we may also use XPath syntax to navigate through an XmlDocument

XmlReader – provides a fast forward-only way of reading XML data

XmlWriter – provides a fast forward-only way of writing XML data


An easy example to get started

The “…XML AdRotator” example is a good way to get started with XML.

Create an “advertisements” file using Visual Studio’s XML Editor. Make sure you select the ad rotator schema.

Then, on a web form, place an AdRotator web server control. Configure it with an XML data source, and specify the advertisements file.


Editing XML programmatically

The .NET Framework is well-equipped for XML work. Any operation you can contemplate can be done. Whether you should be able to do any operation is the subject of debate.

Editing XML in-place, by adding nodes, and/or updating etc., can be done. There are a few concepts to master, and programming techniques to employ, but it can be done. However, the experience can be similar to watching sausage being made – the result can be pretty good, but it’s a pretty ugly process.

If you’re interested in doing these kinds of tasks, check the coverage in the “bonus” post.

For this course, we’re going to adopt the attitude that XML is a “text-based language-independent data interchange format”. We’ll focus on the “data interchange” part. The result is that we should never contemplate using XML as a persistent store format for CRUD operations – we should use a database-like store. We can then use classes that generate and consume XML, while performing operations on the objects in the backing store.


The XML Document Object Model (DOM)

Here is some introductory information about the XML DOM.

The XML Document Object Model (DOM) is an in-memory representation of an XML document. It tells us the following:

  • The XmlNode object represents a node, and is the basic object in the DOM tree
  • For random (navigable) access to nodes, XPath is used

In Mapping the Object Hierarchy to XML Data, we learn the following:

  • Nodes typically become XmlElement node types
  • A node’s text is typically an XmlText node type

Reading an XML Document into the DOM is an easy and trivial task:

  • We can read XML from a string, stream (file), or URL
  • The Load() method is used to do so

When Saving and Writing a Document, there is a fairly easy way to add nodes to an XML document:

  • In XmlDocument, use the CreateNode() or CreateElement() methods, then
  • Use the AppendChild() or InsertAfter() methods to add the new node(s) to the DOM


XML documents – hierarchical and table-oriented

XML documents can contain hierarchical or table-oriented data. A hierarchical document can even have table-oriented parts to it, like a master-detail record.


Using XmlReader and XmlWriter

Look for more coverage of these technologies in a separate blog post, titled “Providing a RESTful web service endpoint…”.


Categories: 2010 Winter BTI420
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: