An Introduction to XML


XML is a tagged markup language similar to HTML. In fact, XML and HTML are distant cousins and have their roots in the Standard Generalized Markup Language (SGML). This means that XML leverages one of the most useful features of HTML - readability. However, XML differs from HTML in that XML represents data, whereas HTML is a mechanism for displaying data. The tags in XML describe the data, as shown in the following example:

  <?xml version="1.0" encoding="utf-8" ?> <Movies>   <FilmOrder name="Grease" film quantity="21"></FilmOrder>   <FilmOrder name="Lawrence of Arabia" film quantity="10"></FilmOrder>   <FilmOrder name="Star Wars" film quantity="12"></FilmOrder>   <FilmOrder name="Shrek" film quantity="14"></FilmOrder> </Movies> 

This XML document represents a store order for a collection of movies. The standard used to represent an order of films would be useful to movie rental firms, collectors, and others. This information can be shared using XML for the following reasons:

  • The data tags in XML are self-describing.

  • XML is an open standard and supported on most platforms today.

XML supports the parsing of data by applications not familiar with the contents of the XML document. XML documents can also be associated with a description (a schema) that informs an application as to the structure of the data within the XML document.

At this stage, XML looks simple - it’s just a human-readable way to exchange data in a universally accepted format. The essential points that you should understand about XML are as follows:

  • XML data can be stored in a plain text file.

  • A document is said to be well formed if it adheres to the XML standard.

  • Tags are used to specify the contents of a document - for example, <FilmOrder>.

  • XML elements (also called nodes) can be thought of as the objects within a document.

  • Elements are the basic building blocks of the document. Each element contains a start tag and end tag. A tag can be both a start and an end tag in one - for example, <FilmOrder />. In this case, the tag specifies that there is no content (or inner text) to the element (there isn’t a closing tag because none is required due to the lack of inner-text content). Such a tag is said to be empty.

  • Data can be contained in the element (the element content) or within attributes contained in the element.

  • XML is hierarchical. One document can contain multiple elements, which can themselves contain child elements, and so on. However, an XML document can only have one root element.

This last point means that the XML document hierarchy can be thought of as a tree containing nodes:

  • The example document has a root node, <Movies>.

  • The branches of the root node are elements of type <FilmOrder>.

  • The leaves of the XML element, <FilmOrder>, are its attributes: name, quantity, and filmId.

Of course, we’re interested in the practical use of XML by Visual Basic. A practical manipulation of the example XML is to display, for example, for the staff of a movie supplier, a particular movie order in an application so that the supplier can fill the order and then save the information to a database. This chapter explains how you can perform such tasks using the functionality provided by the .NET Framework class library.




Professional VB 2005 with. NET 3. 0
Professional VB 2005 with .NET 3.0 (Programmer to Programmer)
ISBN: 0470124709
EAN: 2147483647
Year: 2004
Pages: 267

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net