|
|
| An HTML document is often called a page, since that's how it appears when displayed on a web browser. In html++ parlance, a page is represented by the htmlPage class. The htmlPage class encapsulates the <HTML>, <HEAD>, and <BODY> sections of an HTML document. htmlPage also provides support for persistent cookies via the Cookie() method.
|
|
|
| To construct pages in memory using html++, you combine objects using the << insertion operator or the Add() methods of the objects being manipulated. These objects can be freely combined, then added (or inserted) to an htmlPage object, which then can be output to any C++ stream, such as cout (the most common choice) or a file.
|
|
|
| Let's create a short html++ application that produces a basic page. The C++ code appears below:
|
|
|
| |
|
|
|
|
| This example illustrates the basic components of an HTML page. Note how html++ managed the <HTML>, <HEAD>, <TITLE>, and <BODY> tags, placing the text in the correct position, even though the C++ application didn't specifically mention them.
|
|
|
| In the example, the text passed as the argument to the htmlPage constructor is used as the title of the document, appearing within the <TITLE> section of the <HEAD> section. The << insertion operator was used to insert the "Welcome..." text into the htmlPage object, which htmlPage automatically added to the <BODY> section.
|
|
|
| Notice that the first line of the program output is "Content-Type: text/html". This is called a header, not to be confused with the <HEAD> tag. Headers are interpreted by the web server before delivering the document to the browser. If outputting a page to something other than a web server, you may not want to include the Content-Type header. In such cases, you can pass the page_non_cgi enumeration as an argument to one of the htmlPage constructors. Headers have other purposes as well. For an example of using headers to redirect a browser to another site, see the Advanced Topics section.
|
|
|
| From time to time, you may want to assemble a piece of a document for insertion within another document, such as when using server-side includes. In such cases, html++ may not be used to generate the entire page, which may already contain it's own <HTML>, <HEAD>, and/or <BODY> tags. html++ provides two solutions to this situation:
|
|
|
| |