XML
& Delphi
What
is XML?
- XML (Extensible Markup Language) is a meta-language
- a language used to describe other languages specific to
a narrow domain.
- MS used XML to create the Channel Definition
Format (CDF), an XML implementation for the
creation of push sites in IE.
- Chemical Markup Language (CML) is an XML
implementation specifically for use in documents
that describe chemical structures.
- XML structure:
- "well-formed" document:
- XML is case sensitive & supports multiple languages
- every XML document must start with an XML
processing tag: <?XML version =
"nnn"?>
- hierarchical collection of tags &
elements:
<TagName....attributes....></TagName>
- tags cannot end in a different context from which
they started
- you must close all tags even empty tags: (eg.
< tagname /> but avoid: <tagname>
</tagname> which may cause problems)
- requires either single or double quotes around
attribute values - everything is regarded as a string
in XML
- attribute values cannot reference external
entities
- optionally:
- raw text is usually referred to
as PCDATA
- comments
- non-XML streams
- XML "processing"
instructions
- XML entities (macros that are
expended in the XML stream)
- "Valid" document:
- structure is described by a Document Type
Definition (DTD) which is similar to the
way a data table is structured (ie.
fields)
- as an analogy, the DTD is like a COM
interface & an XML document that
implements that DTD is like a COM object
that creates an instance of it.
- thus the XML file will need to have a line similar to
the following at its header:
- <!DOCTYPE document_type_declaration_name
PUBLIC|SYSTEM "{catalog id | uri | internal DTD
declarations}">
- Document Type Definition:
- parsed entities (those which the XML parser
handles):
- <!ENTITY entity_name entity_value >
- <!ELEMENT element_name (sub-element1,
sub-element2, etc)>
- unparsed entities (those which XML parser
itself does not handle, eg. displaying images; playing
sound):
- MUST be preceded by <!NOTATION ...>
clause:
- <!NOTATION gif89a PUBLIC
"-//CompuServe//NOTATION Graphics
Interchange Format 89a//EN"
"gif">
- <!ENTITY gif89a SYSTEM
"gif89a.gif" NDATA gif89a>
- <!ELEMENT image EMPTY>
- <!ATTLIST image source CDATA #REQUIRED
alt CDATA #IMPLIED type NDATA gif89a>
-
- Comparison with HTML:
- XML is not a new version that will replace HTML
on the web, because it has a different goal.
- HTML is a display language which uses tags to
allow a browser to display the document in a
specific way, but does not provide structure or
describe the data within the document
- an XML document is an hierarchical collection of
elements (tags) & their content which allows
automatic processing so that particular elements
can be:
- easily searched for
- formatted for a variety of outputs
- exported
- unlike HTML, you can't use XML to display the
information in a nicely formatted way in a
browser, however, to achieve this, one uses an Extensible
Style Language (XSL) filter which
defines a set of rules that convert an XML
document to a display language like HTML,
- thus XML + XSL => XSL
processor => HTML output
- unlike HTML, you can't reference one document
from another by using tags such as <A HREF>
or by use of bookmarks such as <A NAME>,
instead one can reference other XML documents
using XML Linking Language (XLL)
and the Xpointer definition.
- W3C's Document Object Model (DOM)
which provides a standard way to access the
hierarchy of elements in an XML document from
applications
- XQL is a query language for XML
data
- XML islands allows embedding of
XML data in HTML documents
- Reading XML documents:
- applications that need to read & process data
stored in XML format use an XML parser which may
be one of two types:
- validating parsers:
- these check that the document
conforms to a Document Type
Definition (DTD) & implements
the rules of the particular DTD
that is declared in the header of
the document
- non-validating parsers:
- these ensure that the document is
well formed but do not validate
it against a DTD
-
Reading XML documents using
Delphi:
- Parsing XML requires an XML parser, the options include:
- creating a parser from scratch
- purchasing a 3rd party solution
- use a "system" tool:
- MS IE:
- versions:
- v4.0 shipped with
msxml.dll which is a
non-validating parser
that doesn't support DOM
- v5.0: supports DOM
- implementation in Delphi:
- OLEAutomation:
- use XMLDoc :=
CreateOLEObject('msxml');
see DI July 1999
- Interfaces:
TXMLBroker:
- Delphi 5 has a TXMLBroker component which is used in a
similar way to TClientDataset except that it uses XML
data packets instead of OLEVariants.
- A webMIDAS client:
- this allows one to easily create a web server
that connects to an application server via DCOM
to generate interactive web client HTML pages
with data grids, data navigation, apply updates
buttons.
- Delphi utilises DCOM, MIDAS, XML, java script and
HTML to achieve this.
- A TXMLBroker component is placed on a web server
application:
- which has a TDCOMConnection component
that connects to your application server
- the TXMLBroker connects to:
- the TDCOMConnection to get its
data
- several TPageProducers to
generate the required HTML pages:
- ppResponse - via the
ResponseProducer property
=> applyUpdates result
- ppReconcile - to handle
update errors similar to
the RecError.pas form
- MidasPageProducer - generates the
main HTML in a web page you
design in Delphi
- Deployment involves:
- place the compiled ISAPI DLL to a place
capable of running script code (eg.
..\inetpub\scripts)
- place WebMIDAS java scripts in folder as
indicated in
TMidasPageProducer.IncludePathURL
- then just open HTML page in web browser
- eg.
http://dmisernt/scripts/empservxml.dll/MidasPageProducer1
- assumes you specified
TWebModule.Actions[0].PathInfo=MidasPageProducer1
- see also: DI Aug 1999 p40-41
References:
- DI July 1999 - Introducing XML & using IE4's
msxml.dll
- DI Mar 2000 -
- Net references: