[ Team LiB ] Previous Section Next Section

Best Practices for Working with XML

In this section, we see some of the best practices we can adopt while working with XML.

Custom Validation

Sometimes, XML validation may be overkill. The parser usually performs several types of validations, and if you don't want all those happening, you can write custom code, in your SAX handler or while traversing your DOM hierarchy, to perform the required validations and turn the parser validation off. This will improve the performance of your XML application.

Using External Entity Resolution

It's faster to access entities from the local machine than over the network. Because of this, use external entity resolution to cache the entities locally. This is also bound to improve performance.

Using JAXP

JAXP is an open standard for parsing XML documents. Although it uses DOM or SAX underneath, using JAXP is preferable to using a the underlying parser directly. This provides you with the flexibility of changing the parser if necessary. Also remember that to take advantage of certain features of WebLogic Server (such as the XML registry), you should use JAXP.

Schemas Versus DTDs

In terms of validation of an XML document, XML schemas are much more powerful than DTDs. Schemas enable you to validate both the structure and the data elements of an XML. Therefore, it's a good idea to code your XML to a schema, rather than a DTD.

Considering the Type of Parser

It's important to choose the parser well. If your application does not require a DOM tree, you should not use DOM. DOM consumes a lot more memory and is performance intensive. SAX, on the other hand, is event based, so it provides better performance.

XML Design

Designing an XML efficiently is an important aspect of ensuring good performance for your application. It's important to keep the XML format simple and well formatted. There are several design patterns available for designing a good XML document. You can refer to the Web site at http://www.XMLPatterns.com for a discussion of some of these patterns.

    [ Team LiB ] Previous Section Next Section