XML Resources
Extensible Markup Language



 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Storing object data as XML
Dec 31, 2001 | TechRepublic, Inc.
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. Let’s look at 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 objects must be persisted in a transactional fashion, the stored data must be represented in a database. Several approaches are available to solve this problem, but there are serious drawbacks. One, for example, uses a mapping algorithm to specify how a piece of the object maps to one or more tables in a relational database model. The benefit of this approach is that it takes advantage of a proven storage mechanism. The drawback is 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 Document Type Definition (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.
A serialized solution
XML can help you facilitate object persistence, a common development issue. By serializing object data to XML, you can create a text-oriented version of an object. Then, by using the BLOB field type, you can store the XML document in the database.