STORING OBJECT DATA AS XML One of the benefits of XML over other data formats is that it closely resembles the structure of object data. Because much of today's design and development is object-based, it's no surprise that when the data is being passed around, it is often represented as XML. However, when it comes to storing this data, there can be a couple of speed bumps along the way. This week's tip addresses a couple of these hurdles. PERSISTENT OBSTACLES Taking a binary object such as a Java class and storing it in a database is called persistence. An instantiated object uses persistence so that it doesn't need to remain in memory the entire time it's being used. Imagine a large processing system handling thousands or millions of transactions per day. Keeping all of these objects in memory would be inefficient and destructive. To accommodate this volume, the objects are stored somewhere when not in immediate use. When the object needs to be used again, it is reinstantiated from the stored data and processed. Because there is the need to persist objects in a transactional fashion, there is also a need to represent the stored data in a database. Several approaches are available to solve this problem. Some architectures use a mapping algorithm to specify how a piece of the object maps to one or more tables in a relational database model. This approach is good because it takes advantage of a proven storage mechanism. This approach is also bad in that each piece of data must be mapped into and back out of the database. This mapping can lead to issues with both data integrity and performance. THE XML APPROACH A different approach, one that avoids the mapping issue, is to use XML. By using a single table with a few key fields, you can create the necessary object lookups and references. In addition, you can use a Binary Large OBject (BLOB) field to store the entire object as a serialized XML string. Most databases support some type of BLOB field for handling large binary data fields and other unsized raw data formats (such as XML documents). Serialization is the process of converting a composite structure, such as an object, into a series of defining elements (in other words, translating the data elements of the object into a series of XML elements representing the data in the object). The set of data stored in the database defines the object's state. By defining an XML DTD that contains all of the object's structured data, you can create an XML document that represents the instance of the object you want to serialize. And by using a BLOB data field, you can store the full XML data without worrying about running into the size constraints of traditional field types. SUMMARY XML can be used to help facilitate object persistence, a common development issue. By serializing object data to XML, one can create a text-oriented version of an object. Using the BLOB field type allows you to store the XML document in the database. ------------------------------------------