Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
XML Streams Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

4.2 The Difference Between Enhanced Streams and Basic Streams

Enhanced XML streams differ from the basic XML streams in several important ways.

First, the input processor for enhanced XML streams is a true XML parser with full support for namespaces and no restrictions regarding ordering of elements or attributes. The enhanced XML input stream uses tag names to locate elements rather than position, as does the basic XML stream. For this reason, the parser tolerates missing and unordered elements. The input stream parses each level of an XML document fully and then pulls appropriate data using an element's tag name. Using this approach, missing or extra elements have no adverse affect, and elements no longer need to be ordered. All of this results in a more forgiving and robust processor.

Next, the enhanced XML output stream also produces a far more natural-looking XML document. Rather than translating every C++ object into a single restricted schema, the enhanced XML streams produce documents tailored to each class. Each class therefore matches a particular schema.

The example in the following section illustrates these differences.

4.2.1 Comparison Example of Basic XML Streams with Enhanced XML Streams

Consider the following class.

You can create an object of this class initialized as follows.

Then you can serialize the object with the original XML object streams as follows.

This will produce the following XML document (namespace definitions have been omitted for brevity's sake).

In order for the original XML input stream to extract such an object, the XML must appear exactly like the above code (allowing for the omitted namespace declarations). Any deviation, such as a missing attribute or an extra rw:member element, will cause the extraction to fail.


The XML must be written in the exact form as is the above code block. If not, the input stream will be unable to perform the extraction.

However, with the enhanced XML stream, you use exactly the same pattern...

...But you get a different result. The first of the following XML documents would be produced by the output stream, but any of them could be read successfully by the input stream (although the one with a missing element would produce an object with a different value, since the title_ member will be initialized to a default value).

You can also use global function RWInsertWithName() in RWTInsertProxy (from the Advanced Tools Module) to give the book element an instance name. For example, you can rewrite the insertion as follows.

Now you get the following document.

The following example shows how to use the enhanced XML object streams to serialize and deserialize a simple object.



Previous fileTop of DocumentContentsIndex pageNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.