Xport Interface: document::body
Returns a pointer to the body
element, if present.
markup* document::body();1st Variety
const markup* document::body() const;2nd Variety
Parameters
none
Returns
A pointer to the body
element, if present. If the body
element isn't present, returns NULL.
Remarks
This operation is one of the more common operations in document
. This operation returns a pointer to the body element, if present in the
document, which provides a very convienient way to access markup objects
in the body of the document, and to add markup to the body as well. This function can also be called to check or verify that the body
element exists.
Complexity
Constant
Example
#include "xhtml_doc.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
*doc.body() << (element(h1) << "Sample Document");
markup::iterator it = doc.body()->insert(element(p));
*it << "This document was created to illustrate document's body() operation.\n"
<< "The body() operation allows easy access to the documents <body> element\n"
<< "for inspection, or for adding content. The body() operation is just one of four\n"
<< "operations in document, for accessing root elements. All four root element accessors\n"
<< "are listed below";
it = doc.body()->insert(element(ul));
*it << (element(li) << "html()");
*it << (element(li) << "head()");
*it << (element(li) << "title()");
*it << (element(li, "red_item") << "body()");
*it << (element(li) << "frameset()");
stylesheet ss;
stylesheet::iterator sit = ss.insert(stylesheet_rule("h1"));
*sit << declaration(css::color, "blue")
<< declaration(text_align, "center");
sit = ss.insert(stylesheet_rule("#red_item"));
*sit << declaration(css::color, "red");
doc.insert(ss);
formatter fmtr(std::cout);
fmtr.option(max_line_length, 70);
doc.write(fmtr);
return 0;
}