Examining the XML Output
Finally, the example writes to standard out two forms of the serialized object. You’ll also use the rwInsertWithName() global method in order to provide an instance name for the book object.
 
{
RWObjectOutputStream out = //1
RWEnhancedXmlObjectOutputStreamImp::make(cout);
out << rwInsertWithName("book2",book2); //2
}
cout << endl;
{
RWObjectOutputStream out = //3
RWXmlObjectOutputStreamImp::make(cout);
out << rwInsertWithName("book2",book2); //4
}
return 0;
}
//1 Sets up an enhanced XML output stream.
//2 Streams the enhanced version of the book2 object to standard out.
//3 Sets up an XML output stream with no transformation support.
//4 Streams the standard XML streams version of the book2 object to standard out.
Here is the resulting output:
In enhanced XML stream format:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<book2
xmlns:rw="http://www.roguewave.com/xmlstream" rw:class="book"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
xsi:type="rw:nested_object">
<title xsi:type="xsd:string">To Love and Be Wise</title>
<author xsi:type="xsd:string">Josephine Tey</author>
</book2>
In ordinary XML stream format:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rw:nested_object rw:name="book2" rw:class="book"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:rw="http://www.roguewave.com/xmlstream">
<rw:member rw:name="title" xsi:type="xsd:string">To Love and Be
Wise</rw:member>
<rw:member rw:name="author" xsi:type="xsd:string">Josephine
Tey</rw:member></rw:nested_object>
If you need to control the format of the data within the XML stream, the streams classes have a make() function that takes a pointer reference to an std::ios object. The constructor for the XML stream fills this pointer with the address of a formatting object for the underlying character stream. Here is an example for the class RWEnhancedXmlObjectOutputStreamImp.
 
std::ios* formatter; // uninitialized pointer
RWObjectOutputStream xostr =
RWEnhancedXMLObjectOutputStreamImp::make(
outfile,script,formatter);
formatter->precision(15); // manipulate data format
The following classes contain a make() function that supports a formatting object: