Chapter 7. Technology options 125
Table 7-1 Technology options across the patterns
7.2 XML
Extensible Markup Language (XML) allows you to specify your own markup
language with tags defined in a Document Type Definition (DTD) or XML
Schema. XML can be used as a means to specify the content of messages
between servers, whether the two servers are within an enterprise or represent a
business-to-business connection.
The critical factor here is the agreement between parties on the message
schema, which is specified as an XML DTD or Schema. An XML parser is used
to extract specific content from the message stream. Your design will need to
consider whether to use an event-based approach, for which the SAX API is
appropriate, or to navigate the tree structure of the document using the DOM
API.
The IBM XML4J XML parser was made available through the Apache open
source organization under the Xerces name. For open source XML frameworks,
see:
http://xml.apache.org/
Business Drivers
Direct Connection
Exposed Direct
Connection
Broker
Exposed Broker
Serial Process
Exposed Serial
Process
Parallel Process
XML üüüüüüü
Web services üüüüüüü
J2EE Connector Architecture üü
Java Message Service (JMS) üüüüüüü
Message-oriented Middleware üüüüü
Flow languages üüü
126 Broker Interactions for Intra- and Inter-enterprise
7.2.1 Defining XML documents
XML documents are defined using DTDs or XML Schemas.
DTDs are a basic XML definition language, inherited from the SGML
specification. The DTD specifies what markup tags can be used in the document
and what their structures are.
DTDs have two major problems:
򐂰 Poor data typing: In DTDs, elements can only be specified as EMPTY, ANY,
element content, or mixed element-and-text content, and there is no standard
way to specify null values for elements.
Data typing like date formats, numbers, or other common data types cannot
be specified in the DTD, so an XML document may comply with the DTD but
still have data type errors that can only be detected by the application.
򐂰 Not defined in XML: DTD uses its own language to define XML syntax that is
not compliant with the XML specification. This makes it difficult to manipulate
a DTD.
To solve these problems, the World Wide Web Consortium (W3C) specified a
new standard to define XML documents called XML Schema. XML Schema
provides the following advantages over DTDs:
򐂰 Strong typing for elements and attributes
򐂰 Standardized way to represent null values for elements
򐂰 Key mechanism that is directly analogous to relational database foreign keys
򐂰 Defined as XML documents, making them programmatically accessible
Even though XML Schema is a more powerful technology to define XML
documents, it is also a lot harder to work with, so DTDs are still widely used to
define XML documents. Additionally, simple, non-hard-typified documents can be
easily defined using DTDs with similar results to using XML Schema.
Whether to use one or the other will depend on the complexity of the messages
and the validation requirements of the application. Actually, in many cases both a
DTD and an XML Schema are provided, so they can be used by the application
depending on its requirements.
Note: Remember that the validation process of an XML document using XML
Schemas is an
expensive process. Validation should be performed only when it
is necessary.

Get Patterns: Broker Interactions for Intra- and Inter-enterprise now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.