Delphi Developer's Guide to XML - Code Examples

The Delphi listings function in Delphi 4 and up (except for new technology introduced in later versions).

Zipped Download all the code in one go.

You will still need the various third-party XML packages for those projects that reference them.

Part 1 - Introduction to XML

Part 2 - The Document Object Model

Part 3 - Simple API for XML

Part 4 - Serving XML

Part 5 - Delphi XML Tools

Part 6 - XML in Use


Part 1 - Introduction to XML

Chapter 1 - History

An overview of XML, its origins and purpose. Several XML applications are highlighted including XHTML, MathML, SVG, SMIL, and RDF.

Chapter 2 - XML Syntax

Basic XML syntax, including elements and attributes, text and white space, processing instructions, CDATA sections, the XML prolog, and XML processors.

Chapter 3 - Document Type Definitions

DTDs describe the structure of classes of XML documents and provide the basis for their validation.

Chapter 4 - XML Schema

As an alternative to DTDs, XML Schema also let you define the structure of a class of XML documents. They provide additional functionality, especially in typing data content, and are themselves XML documents.

Chapter 5 - XPath and XPointer

XPointer enhances XLink to let you refer to parts of a resource. It builds on the XPath definition to provide a language for describing these sub-sections.

Chapter 6 - Extensible Stylesheet Language and Transformations

XML is designed to encode the content for an area of interest. Presentation abilities come from XSL and XSLT. Transformations let you convert your XML data into HTML, text, or even other XML documents.

Chapter 7 - XLink

The Extensible Linking Language (XLink) supplies abilities beyond the simple linking of HTML, including multiple paths, bi-directional paths, and fully external links.

Back to the top

Part 2 - The Document Object Model

Chapter 8 - The Document Object Model

The DOM specification defines a standardized way of accessing or constructing an XML document. It models the hierarchical structure of a document through objects in memory.

Chapter 9 - Microsoft's Document Object Model

Microsoft's DOM provides most of the requirements of the standard DOM, while adding several essential extras. It also supports using XSLT on the document.

Chapter 10 - Open XML's Document Object Model

Open XML's DOM provides the same basic support as the previous implementation, but adds much extra functionality in the handling of internal and external DTDs. Open XML is a set of native Delphi classes, and is an open source project.

Chapter 11 - The Common DOM Framework

Introduced in Delphi 6, there is now a common set of DOM interfaces in Delphi. Several standard adapter units are available to allow various DOM implementations to be used through this framework, including Microsoft's and Open XML's. Additional adapters are available here for TurboPower's XML Partner and CUESoft's CUEXml package.

Back to the top

Part 3 - Simple API for XML

Chapter 12 - Simple API for XML

SAX provides an alternative way of parsing XML documents. It uses an event-based approach, calling nominated handlers at appropriate times. Thus, it does not need to hold the entire document in memory at the one time (as DOM does).

Chapter 13 - Microsoft's SAX Parser

Microsoft provides a SAX2-compliant parser with its XML package.

Chapter 14 - SAX for Pascal

An all-Pascal version of the SAX interfaces is available as the result of an open source project. Although this is not a standard part of the Delphi distribution it operates with many Delphi versions, and allows you to use many SAX-based or SAX-like parsers, including Microsoft's, Open XML, TurboPower's XML Partner, and Destructor.

Back to the top

Part 4 - Serving XML

Chapter 15 - XML is Data

XML is really data, formatted to be both human and machine-readable. The source of this data is often a database. Included here is the movie-watcher database for use throughout the rest of the book.

Chapter 16 - Simple Text

Since XML is just text, you can easily generate it from a database as a string value.

Chapter 17 - Web Modules

Normally Delphi's Web modules deliver HTML back to the client, but there is no reason not to send XML instead. Again the XML comes form the database and is sent directly to the client.

Chapter 18 - DOM Generation

The DOM is designed to provide full-cycle handling of XML documents, from parsing, to generation and modification. Separate programs demonstrate each DOM in turn.

Chapter 19 - SAX Generation

With Microsoft's XML package comes the IMXWriter interface, a content handler than generates XML. And you can drive it programmatically to create your own documents. Similarly, components in the SAX for Pascal package let you achieve the same outcome.

Chapter 20 - Applying XSL Transformations

XSLT lets you transform XML content into other formats, often HTML, but also including straight text and RTF. Again Microsoft's DOM is used to perform the transformations.

Chapter 21 - XML Broker

Delphi 5 can use XML between a MIDAS server and client. Tie this client to a Web module and add Delphi's InternetExpress components and you have a Web front-end to your database.

Back to the top

Part 5 - Delphi XML Tools

Chapter 22 - XML Data Binding

Data binding extends the common DOM framework to provide "real-world" objects, complete with properties, that represent the data in your XML document. A wizard generates the binding for you, allowing you to almost forget that the data came from an XML document. You can both read and update the underlying XML through the binding.

Chapter 23 - XML Mapper

A separate tool, the XML Mapper creates transformation definitions that let you convert an arbitrary XML document to and from the XML format used by client datasets. Using these transformations, you can load an XML document into a dataset, modify it using standard data-aware components, then save the changes back to the original document.

Chapter 24 - SOAP and Web Services

SOAP defines a messaging framework that can be used for remote procedure calls - better known as Web services. Wizards assist in the creation of your own Web services, and in the importing of definitions for existing Web services.

Back to the top

Part 6 - XML in Use

Chapter 25 - Examination XML - Delphi Client

A Delphi client for XML documents that define examinations. Microsoft's DOM provides the parsing abilities, transforming the XML into a customized object model.

Chapter 26 - Examination XML - Web Client

Demonstrating the separation of content from presentation, this application reuses objects from the previous version to provide a Web-based interface to the examinations. It uses XSLT to convert the basic XML into HTML for display, based on Microsoft's XSLT engine.

Chapter 27 - XML Building Blocks

Built on top of the Common DOM framework of Delphi 6 and 7, XML Building Blocks is a suite of components that allow you to create plug-and-play XML applications.

Back to the top


Appendix A - CUESoft Document Object Model

CUESoft's DOM supports most of the standard DOM too. It is a set of native Delphi classes.

Appendix B - Mass Electronic Mail-Outs

Perform mass mail-outs using information from a database. XML provides the configuration parameters and the message template. Other standards allow database access (SQL) and e-mail functionality (SMTP), while a modular approach reduces ongoing maintenance. The Microsoft DOM provides the XML parsing abilities.

Appendix C - A Customized Client

Although XML provides a standardized way of dealing with classes of documents, frequently a customized client gives a more user-friendly interface. This Delphi application handles the movie-watcher documents using a native SAX for Pascal parser.

Back to the top

Delphi Developer's Guide to XML 2003, Keith Wood