4.2. Outline for Handling XML Documents

An XML-based application, and in particular a Web service application, may consume or produce XML documents, and such an application may implement three distinct processing phases:

  1. The application consumes an XML document.

  2. The application applies its business logic on information retrieved from the document.

  3. The application produces an XML document for response.

Generally speaking, an XML-based application exposes an interface that is defined in terms of the schemas for the XML documents that it consumes and produces as well as by the communication or interaction policies of the application. In the case of a Web service, a Web Services Description Language (WSDL) document describes this interface, and this document refers to the XML schemas to which the exchanged documents conform.

Let's examine the steps for handling XML documents. (See Figure 4.1.) The first phase, consuming XML incoming documents or XML input processing, consists of the following steps:

1.
Parse and optionally validate the document— Parse and validate the incoming document against the schema to which the document should conform.

2.
Transform the document— If necessary, transform the document from its conforming schema to the internally supported schema.

3.
Disassemble the document or pass it as is to the next phase— Disassembling a document consists of these steps:

  • Search the incoming document for relevant information. The information can be recognized by using the embedded tags or its expected location within the document.

  • Extract the relevant information once it is located.

  • Optionally, map the retrieved information to domain-specific objects.

Figure 4.1. Activity Diagram Modeling Typical Steps for Handling XML Documents


In the second phase, the application applies the business logic. This entails actually processing the input information retrieved from the XML document. Such processing is considered document-centric when the logic handles the document directly, or object-centric when the logic is applied to domain-specific objects to which the retrieved information has been mapped. As a result of this processing, the application may generate XML output information, which is the third phase.

The steps for this third phase, XML output processing, mirror that of XML input processing. Producing XML output consists of the following steps:

1.
Assemble the document— Assemble the output document from the results of applying the application's logic.

2.
Transform the document— If necessary, transform the document from the internally supported schema to the appropriate external vertical schemas.

3.
Optionally validate, then serialize, the document— Validating prior to serializing the output document is often considered optional.

It is quite possible that an XML-based application may only implement some of these phases, generally those that apply to its services. For example, some applications use XML just for configuration purposes, and these applications may only consume XML documents. Other applications just generate device-targeted content, and these applications may only produce XML documents (Wireless Markup Language, HTML, SVG, and so forth). E-commerce applications, on the other hand, may both consume and produce XML documents.

There are also applications that specialize in particular operations, such as those that specialize in transformations, in which case they perform only their intended operations. For instance, an application's function might be to select and apply a transformation to a document based on the processing requirements passed with the document, thus producing one or more new documents. In this example, the application's logic may consist only of the style sheet selection logic.

Developers implementing applications with a document-centric processing model—where the business logic itself handles the documents—may find that document handling is more entangled with the business logic. In particular, the steps that may intermingle with the business logic are those to disassemble the consumed documents and assemble the output document. These cases require careful handling. See “Abstracting XML Processing from Application Logic” on page 155.

Clients, whether a Web service peer or a rich client interacting with an end user, implement processes, such as the process just presented, for handling XML documents either submitted along with requests to a service or received as responses. Sometimes the application logic of human-facing rich clients may have to deal with the presentation of received documents to the end user rather than with business logic processing.

Note that real-world enterprise applications may have several instances of this abstract process to handle documents with unrelated schemas or documents with unrelated purposes. Moreover, these processes can actually be implemented to span one or more layers of an enterprise application. In particular, in the case of a Web service endpoint, these phases can be implemented in both the interaction and processing layers, depending on the processing model used by the Web service. See the discussion on a Web services layered architecture in “Key Web Services Design Decisions” on page 61.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset