BEA Logo BEA WebLogic Server Release 6.1

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

   Programming WebLogic XML:   Previous topic   |   Next topic   |   Contents   |  Index

 

XML Overview

 

The following sections provide an overview of XML technology and WebLogic Server:

What Is XML?

Extensible Markup Language (XML) is a markup language for documents containing structured information. It is a simplified version of Standard Generalized Markup Language (SGML). XML has become an industry standard for delivering content on the Internet. Because it provides a facility to define new tags, XML is also extensible.

Like HTML, XML uses tags to describe content. However, rather than focusing on the presentation of content, the tags in XML describe the meaning and hierarchical structure of data. This functionality allows for the sophisticated data types that are required for efficient data interchange between different programs and systems. Further, because XML enables separation of content and presentation, the content, or data, is portable across heterogeneous systems.

The XML syntax uses matching start and end tags to mark up information. Information delimited by tags is called an element. Elements can also have attributes that are defined in the form of name-value pairs.

The syntactic meaning associated with the tags of an XML document is defined in a Document Type Definition (DTD). A DTD describes the elements and attributes that are valid in an XML document, and the contexts in which they are valid. In other words, a DTD specifies which tags are allowed within certain other tags, and which tags and attributes are optional.

Schemas are a recent development in XML specifications and are intended to supersede DTDs. They describe XML documents with more flexibility and detail than DTDs do. The schema specification, currently under development, is a product of the World Wide Web Consortium (W3C) and is intended to address many limitations of DTDs.

Note: In this version of WebLogic Server, the final version of the schema specification is not supported. Therefore, the schema support in this version should be considered experimental; it should not be used in a production environment.

Why Use XML?

An industry typically uses data exchange methods that are meaningful and specific to that industry. With the advent of e-commerce, businesses conduct an increasing number of relationships with a variety of industries and, therefore, must develop expert knowledge of the various protocols used by those industries for electronic communication.

The extensibility of XML makes it a very effective tool for standardizing the format of data interchange among various industries. For example, when message brokers and workflow engines must coordinate transactions among multiple industries or departments within an enterprise, they can use XML to combine data from disparate sources into a format that is understandable by all parties.

Learning About XML

To learn about XML, see the following online courses and tutorials:

What Are XSL and XSLT?

The Extensible Stylesheet Language (XSL) is a W3C standard for describing presentation rules that apply to XML documents. XSL includes both a transformation language, (XSLT), and a formatting language. These two languages function independently of each other. XSLT is an XML-based language and W3C specification that describes how to transform an XML document into another XML document, or into HTML, PDF, or some other document definition format.

An XSLT processor accepts as input an XML document and an XSLT document. The template rules contained in an XSLT document include patterns that specify the XML tree to which the rule applies. The XSLT processor scans the XML document for patterns that match the rule, and then it applies the template to the appropriate section of the original XML document.

Common Uses of XML and XSLT

How you use XML and XSLT depends on your particular business needs.

Using XML and XSLT to Separate Content from Presentation

XML and XSLT are often used in applications that support multiple client types. For example, suppose you have a Web-based application that supports both browser-based clients and Wireless Application Protocol (WAP) clients. These clients understand different markup languages, HTML and Wireless Markup Language (WML), respectively, but your application must deliver content that is appropriate for both.

To accomplish this goal, you can write your application to first produce an XML document that represents the data it is sending to the client. Then the application can transform the XML document that represents the data into HTML or WML, depending on the client's browser type. Your application can determine the client browser type by examining the User-Agent request header of an HTTP request. Once the application knows the client browser type, it uses the appropriate XSLT style sheet to transform the document into the correct markup language. See the SnoopServlet example included in the examples/servlets directory of your WebLogic Server distribution for an example of how to access this type of header information.

This method of rendering the same XML document using different markup languages in respective client types helps concentrate the effort required to support multiple client types into the development of the appropriate XSLT style sheets. Additionally, it allows your application to adapt to other clients types easily, if necessary.

For additional information about XSLT, see Additional Resources.

XML as a Message Format for Business-to-Business Communication

In a business-to-business (B2B) environment, Company A and Company B want to exchange information about e-commerce transactions in which both are involved. Company A is a major e-commerce site. Company B is a small affiliate that sells Company A's products to a niche group of customers. When Company B sends customers to Company A, Company B is compensated in two ways: it receives, from Company A, both money and information about other customers that make the same sort of purchases as those made by the customers referred by Company B. To exchange information, Company A and Company B must agree on a data format for information that is machine readable and that operates with systems from both companies easily.

XML is the logical data format to use in this scenario, but selecting this format is only the first step. The companies must then agree on the format of the XML messages to be exchanged. Because Company A has a one-to-many relationship with its affiliates, Company A must define the format of the XML messages they will send and accept.

To define the format of XML messages, or XML documents, Company A creates two document type definitions (DTDs): one that describes the information that A will provide about customers and one that describes the information that A wants to receive about a newly affiliated company. Company B must also create two DTDs: one to process the XML documents received from Company A and one to prepare an XML document in a format that can be processed by Company A.

WebLogic Server XML Features

WebLogic Server consolidates XML technologies applicable to WebLogic Server and XML applications based on WebLogic Server. The XML Module is a set of XML components that is installed and integrated automatically when you install WebLogic Server. These components facilitate the development and use of XML applications. Using XML Module and WebLogic Server, customers can build XML applications that use standard parsers, custom-generated parsers, XSLT transformers, and DTDs to process and convert XML files.

Parsing XML Documents

WebLogic Server includes a built-in parser that is based on the Apache Xerces parser version 1.2.0. You can use the built-in parser in either Simple API For XML (SAX) mode or Document Object Model (DOM) mode.

You can also use the parser of your choice for selected XML applications or for all your XML applications: custom-generated parsers, different versions of the Apache Xerces parser, the Sun parser, and so on.You can configure a single WebLogic Server to use one parser for a particular application and use another parser for a different application. WebLogic Server makes parser capabilities available through the XML Registry. To use these capabilities, use the Administration Console to configure the appropriate parser classes in the XML Registry. For more information about using the XML Registry to specify different parsers, see Configuring a Parser Other Than the Built-In Parser.

Generating Custom Parsers

Using the WebLogic Parser Generator you can generate a parser that is tailored for a particular DTD. Generated parsers use the SAX API. They are efficient and fast, but should only parse XML documents that use the same DTD used to generate the parser. For more information about the limitations, behaviors, and performance of generated parsers, refer to:

Validating XML Documents

WebLogic Server supports the use of DTDs to validate XML documents.

As mentioned earlier, an XML DTD contains markup declarations that provide a grammar for a class of documents. An XML document is considered valid if 1) it has an associated DTD, and 2) it complies with the constraints expressed in the associated DTD.

Validation is a powerful tool for ensuring that an XML document contains all the information required by your application. An XML parser automatically checks a document to ensure that it is well-formed, or that it follows all the rules in the W3C Recommendation for XML 1.0. However, to validate a document, you must include in your document either a DTD or a reference to an external DTD. You specify how the DTD will be handled within the document type declaration.

Transforming XML Documents

WebLogic Server includes a built-in XSLT processor that is based on the Apache Xalan-Java XSLT processor version 1.2. You can use this built-in XSLT processor or other XSLT processors in your XML application to transform XML documents. To do so, you must define the processor of choice in your application code. For more information about transforming XML documents, see Transforming XML Documents.

Resolving External Entities

The XML Module supports external entity resolution through the XML Registry. This feature of the registry eliminates the need to construct and set SAX EntityResolvers. To use this feature, open the Administration Console and use the XML Registry to associate the pathnames of local copies of external entities with their Public id and/or System id. These entities are then resolved automatically by WebLogic Server at parse time. For more information about using the XML Registry for external entity resolution, see Using the XML Registry.

WebLogic Server XML Components

The WebLogic Server distribution provides XML components packaged as follows:

All of these components are automatically installed when you install the WebLogic Server distribution.

WebLogic Server includes the basic components needed to build and run XML applications:

Built-in XML Parser

In WebLogic Server Version 6.0, the built-in parser is based on the Apache Xerces parser 1.2.0. This parser replaces the Sun parser that shipped with WebLogic Server 5.1. By default, the built-in parser is used to parse XML documents. Because the built-in parser is in the weblogic.apache.xerces package, it does not interfere with any other version of the Xerces parser that may be defined in the WebLogic Server classpath. If you want to use a different parser, use the WebLogic XML Registry to configure the parser of your choice as the default parser. This design minimizes the work required to write, build, and run XML applications on WebLogic Server that use different parsers.

Note: The built-in parser is in the weblogic.Apache.Xerces package.

WebLogic Integrated Java API for XML Parsing (JAXP) 1.0.1

Java API for XML Parsing (JAXP) 1.0.1 is a Java-standard, parser-independent API for XML. When you use JAXP, you can also use the WebLogic XML Registry to control which parsers are used without having to write application code that is dependent on a particular parser. The use of the XML Registry to configure parsers supersedes the use of the JAXP parser factory system properties, which is the default JAXP mechanism for configuring a parser.

JAXP 1.0.1 supports two modes for processing XML documents: SAX 1.0 and DOM Level 1.

Built-in XSLT Processor

WebLogic Server includes an XSLT processor, which is based on the Apache Xalan-Java XSLT processor 1.2, as the built-in XSLT processor. You can use the Xalan-based processor to transform XML documents into HTML, WML, text, or other XML document types. XSLT transformations are not part of JAXP 1.0.1, so you must use Xalan specific code in your XML application to instantiate and run XSLT transformation using the built-in XSLT processor. Because the Xalan processor classes are provided in the weblogic.apache.xalan package, the built-in XSLT processor does not interfere with any other version of the Xalan XSLT processor that may be defined in the WebLogic Server classpath.

WebLogic XML Registry

The XML Registry simplifies XML administration and configuration tasks by separating these tasks from the XML application. Use the Administration Console (a graphical user interface, or GUI, for WebLogic Server administration) to configure and assign XML Registries.

Note: Each WebLogic Server domain can include any number of registries; each WebLogic Server in a domain can be assigned zero or one registry.

The advantages of the XML Registry are as follows:

You can use the XML registry to perform the following tasks:

All the preceding capabilities are available if your application uses the standard Java API for XML Parsing (JAXP), which is included in this version of WebLogic Server. These capabilities are for use on the server side only.

XML Servlet Attributes

WebLogic Server supports two special XML servlet attributes: org.xml.sax.HandlerBase and org.w3c.dom.Document. These attributes:

Note: The setAttribute and getAttribute methods are provided for convenience only; they are not required to parse XML from a servlet.

XML Module Components

The XML Module is a set of XML components that is installed and integrated automatically when you install the WebLogic Server software (see Figure 1-1). These components facilitate the development and use of XML applications. Specifically, the module components enable the use of the parser generator and the JSP tag library. Although the module components do not make up a separate software package, they perform a discrete set of functions, and are therefore referred to collectively as a module.

Note: The XML Module can be updated and released separately from WebLogic Server.

The XML Module contains the following components:

XML Parser

The XML Module includes the Apache Xerces parser version 1.2.0. In this version of WebLogic Server, this component is functionally the same as the WebLogic Server built-in XML parser.

XSLT Processor

The XML Module includes Apache Xalan-Java XSLT processor 1.2. In this version of WebLogic Server, this component is functionally the same as the WebLogic Server built-in XSLT processor.

WebLogic Parser Generator

The parser generator tool is built by BEA to achieve custom parsing performance while using standard XML APIs. This tool enables you to generate customized SAX parsers that are specific to the document types represented by DTDs. Because each generated parser is built for a specific DTD, it cannot be used to parse XML documents written for other DTDs.

The parser generator is included in xmlx.jar, which is installed when you install your WebLogic Server distribution.

Using the parser generator has advantages and disadvantages. The advantages are better performance while using standard JAXP APIs, a smaller code footprint, and less server resource utilization. The disadvantages are that the parser generator produces a SAX 1.0 parser (instead of SAX 2.0); it is neither a fully validating parser nor a non-validating parser; and it does not support DOM.

After you use this tool to generate a custom parser, you can configure the XML registry in WebLogic Server so that the custom-generated parser is automatically used to parse a particular XML document.

WebLogic XSLT JSP Tag Library

The JSP tag library provides a simple tag that enables access to the built-in XSLT processor from within a Java Server Pages (JSP) running on WebLogic Server. Currently, this tag supports the built-in XSLT processor only; you cannot use the tag to parse an XML document from within a JSP using a different parser.

The JSP tag library is included in xmlx-tags.jar, which is installed when you install your WebLogic Server distribution.

Note: The JSP tag library is provided for convenience only; it is not required to access XSLT processors from within a JSP.

 

Back to Top