Xport Interface: element::write
Writes the element
object, including any children and descendants of the element
, to a file or stream.
virtual void element::write(
const formatter& fmtr
);
Parameters
fmtr
A formatter
object, which determines the output file or stream, and how the xhtml output will be formatted.
Returns
Nothing.
Remarks
This operation is used to write the element object to a file or stream. The beginning and ending tags of the element will be written, and also any
and all content that the element may contain, including nested elements.
This operation is used internally when calling document::write()
. To use this operation, you must first create a formatter
object. When creating a formatter
object, you specify the output file or stream, and any format options for the output.
Complexity
Constant
Example
#include "xhtml_doc.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
// create an xhtml strict root document
document doc(root_doc);
// add some content to the document
*doc.body() << (element(h1) << "Test document");
markup::iterator it = doc.body()->insert(element(p));
*it << "This is a test xhtml document generated by Xport. Xport can generate and parse "
<< "xhtml documents. It can be used for reporting purposes and a variety of other uses. "
<< "Xport is released under the GPL open source license agreement.";
it = doc.body()->insert(element(ul));
*it << (element(li) << "List item 1");
*it << (element(li) << "List item 2");
*it << (element(li) << "List item 3");
// create a formatter object, and set it's output to cout
formatter fmtr(std::cout);
fmtr.option(nesting_indent, 3);
fmtr.option(max_line_length, 70);
// write the html element to cout
doc.html()->write(fmtr);
return 0;
}