Xport Interface: parser::option
Sets or retrieves specific parsing options.
bool parser::option(1st Retrieval Variety
formatter_boolean_option bool_opt
);
int parser::option(2st Retrieval Variety
formatter_integer_option int_opt
);
std::string parser::option(3rd Retrieval Variety
formatter_string_option string_opt
);
std::ostream& parser::option(4th Retrieval Variety
parser_log_stream_option log_ostream_opt
);
logging_verbosity parser::option(5th Retrieval Variety
parser_log_option log_verbosity_opt
);
bool parser::option(1st Setting Variety
parser_boolean_option opt,
bool bool_value
);
bool parser::option(2st Setting Variety
parser_integer_option int_opt,
int int_value
);
bool parser::option(3rd Setting Variety
parser_string_option string_opt,
const std::string& string_value
);
bool parser::option(4th Setting Variety
parser_log_stream_option log_stream_opt,
std::ostream& log_stream_value
);
bool parser::option(5th Setting Variety
parser_log_option log_verbosity_opt,
logging_verbosity log_verbosity_value
);
Parameters
bool_opt
A parser_boolean_option
enumerator which specifies the boolean option to set or retrieve.
int_opt
An parser_integer_option
enumerator which specifies the integer option to set or retrieve.
string_opt
A parser_string_option
enumerator which specifies the string option to set or retrieve.
log_stream_opt
A parser_log_stream_option
enumerator which specifies setting or retreiving the log stream.
log_verbosity_opt
A parser_log_option
enumerator, which specifies that the log verbosity be returned or set.
bool_value
A boolean value which will set the specified boolean option.
int_opt
An integer value which will set the specified boolean option.
string_value
A string value which will set the specified boolean option.
log_stream_value
An output stream which will be used for the log output.
log_verbosity_value
An log_verbosity
enumeration which determines the amount and type of log messages the parser sends to the log stream. Available
enuerators are lv_none
, lv_error
, lv_warning
, lv_start_element
, lv_end_element
, and lv_all
.
Some enumerators overlap for consistancy. The lv_warning
enumerator also includes lv_error
, and the lv_end_element
also includes lv_start_element
.
Returns
In the first setting variety, returns a boolean value disclosing the state of the specified option.
In the second setting variety, returns an integer disclosing the integer value of the specified option.
In the third setting variety, returns a string disclosing the string value of the specified option.
In the forth setting variety, returns an output stream which is used for logging purposes.
In the fifth setting variety, returns a log_verbosity
enumerator, which reveals the logging verbosity.
Remarks
This operation is used to set and retrieve various parsing options of the called parser
object. The various options are described below.
Many more options will be added to the list below, allowing more control of the parsed (x)html input.
All options in parser
are distinguished, set, and retrieved, by enumerations. The table below lists the various options now available in parser
,
and their default values. As more options are added, they will be added to the list.
Option enumerator |
Option type |
Default |
Description |
convert_entities |
boolean |
false |
Determines if character entity references will be converted according to the current entity list, or unaltered. |
preserve_newlines |
boolean |
false |
Determines if newlines in the parsed (x)html will be preseverd or removed. |
strip_byte_order_mark |
boolean |
false |
Determines the byte order mark, if present, will be removed, or included in the output document. |
log_verbosity |
enumeration |
lv_none |
Determines whether logging will take place, and if so, the amount of logging (logging verbosity). |
log_stream |
enumeration |
std::cout |
Determines whether logging will take place, and if so, the amount of logging (logging verbosity). |
Complexity
Constant
Examples
convert_entities example
#include "xhtml_doc.h"
#include <iostream>
#include <sstream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
markup::iterator it = doc.body()->insert(element(p));
*it << "The following character is a greater character: >";
std::ostringstream ostr;
formatter fmtr1(ostr);
fmtr1 << doc;
std::istringstream input(ostr.str());
parser prsr(input);
doc.clear();
formatter fmtr2(std::cout);
doc.parse(prsr);
std::cout << "Parsed output from an unmodified parser.\n\n";
fmtr2 << doc;
std::cout << "\n\n\n";
prsr.option(convert_entities, true);
doc.clear();
doc.parse(prsr);
std::cout << "Parsed output after turning on convert_entity option.\n\n";
fmtr2 << doc;
std::cout << "\n\n\n";
return 0;
}
preserve_newlines example
#include "xhtml_doc.h"
#include <iostream>
#include <sstream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
markup::iterator it = doc.body()->insert(element(p));
*it << "This paragraph consists of multiple sentences\n"
<< "with newlines scattered within. The parser offers\n"
<< "an option to preserve the newlines. If the newlines\n"
<< "are not preserved, a formatter object can write the\n"
<< "the document with a maximum line length.";
std::ostringstream ostr;
formatter fmtr1(ostr);
fmtr1 << doc;
std::istringstream input(ostr.str());
parser prsr(input);
doc.clear();
formatter fmtr2(std::cout);
doc.parse(prsr);
std::cout << "Parsed output from an unmodified parser.\n\n";
fmtr2 << doc;
std::cout << "\n\n\n";
prsr.option(preserve_newlines, true);
doc.clear();
doc.parse(prsr);
std::cout << "Parsed output after turning on preserve_newline option.\n\n";
fmtr2 << doc;
std::cout << "\n\n\n";
return 0;
}
log_verbosity 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 is a sample document which illustrates the parsing capabilities in Xport. ";
*it << "The list below displays some of the features in Xport's parser.";
it = doc.body()->insert(element(ul));
*it << (element(li) << "Logging capabilities");
*it << (element(li) << "Entity processing");
*it << (element(li) << "Newline preservation");
formatter fmtr1("c:/sample.htm");
fmtr1.option(max_line_length, 70);
fmtr1 << doc;
parser prsr("c:/sample.htm");
prsr.option(log_stream, std::cout);
std::cout << "Parsing xport brochure with logging verbosity = lv_none.\n\n";
doc.clear();
doc.parse(prsr);
std::cout << "\n\n\n";
std::cout << "Parsing xport brochure with logging verbosity = lv_error.\n\n";
doc.clear();
prsr.option(log, lv_error);
doc.parse(prsr);
std::cout << "\n\n\n";
std::cout << "Parsing xport brochure with logging verbosity = lv_warnings.\n\n";
doc.clear();
prsr.option(log, lv_warning);
doc.parse(prsr);
std::cout << "\n\n\n";
std::cout << "Parsing xport brochure with logging verbosity = lv_start_tag.\n\n";
doc.clear();
prsr.option(log, lv_start_tag);
doc.parse(prsr);
std::cout << "\n\n\n";
std::cout << "Parsing xport brochure with logging verbosity = lv_start_tag|lv_end_tag.\n\n";
doc.clear();
prsr.option(log, log_verbosity(lv_end_tag|lv_start_tag));
doc.parse(prsr);
std::cout << "\n\n\n";
std::cout << "Parsing xport brochure with logging verbosity = lv_all.\n\n";
doc.clear();
prsr.option(log, lv_all);
doc.parse(prsr);
std::cout << "\n\n\n";
return 0;
}
log_stream example
#include "xhtml_doc.h"
#include <iostream>
#include <fstream>
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 is a sample document which illustrates the parsing capabilities in Xport. ";
*it << "The list below displays some of the features in Xport's parser.";
it = doc.body()->insert(element(ul));
*it << (element(li) << "Logging capabilities");
*it << (element(li) << "Entity processing");
*it << (element(li) << "Newline preservation");
formatter fmtr1("c:/sample.htm");
fmtr1.option(max_line_length, 70);
fmtr1 << doc;
parser prsr("c:/sample.htm");
std::ofstream log_file("c:/logfile.txt");
prsr.option(log_stream, log_file);
prsr.option(log, lv_all);
doc.clear();
doc.parse(prsr);
std::cout << "\n\n\n";
std::ifstream in("c:/logfile.txt");
std::cout << in.rdbuf();
return 0;
}