Xport Interface: markup::styles
For a derived element
object, retrieves all style values, or clears all styles in the element's
style attribute.
virtual std::map<css_property, std::string> markup::styles();1st Variety
virtual const std::map<css_property, std::string> markup::styles() const;2nd Variety
Parameters
none
Returns
Returns a style map, (or const style map in the 2nd variety) which includes the css property/value pairs for all css properties set in the style
attribute for the called element
.
Remarks
This operation is revelant only if it is called on an element
derived object. If called on a pcdata
, comment
,
or procinstr
object, an empty style map will be returned.
When called on a derived element
object, the first variety will return a map of all styles for the called element
. When
called on a non-const element object, a non-const style map is returned, enabling the caller to modify or clear the styles.
Complexity
Constant
Example
#include "xhtml_doc.h"
#include <map>
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
markup::iterator it = doc.body()->insert(element(ul));
markup::iterator li_it = it->insert(element(li) << "item 1");
li_it->style(css::color, "red");
li_it = it->insert(element(li) << "Item 2");
li_it->style(font_weight, "bold");
li_it = it->insert(element(li) << "Item 3");
li_it->style(list_style_type, "square");
formatter fmtr(std::cout);
doc.write(fmtr);
li_it = it->begin();
for (int list_item = 1; li_it != it->end(); ++li_it, ++list_item) {
std::map<css_property, std::string> style_map = li_it->styles();
std::cout << "List item " << list_item << " contains the following in it's style attribute.\n";
std::map<css_property, std::string>::const_iterator mit = style_map.begin();
for (; mit != style_map.end(); ++mit) {
switch (mit->first)
{
case css::color:
std::cout << "color: " << mit->second << "\n"; break;
case font_weight:
std::cout << "font-weight: " << mit->second << "\n"; break;
case list_style_type:
std::cout << "list-style-type: " << mit->second << "\n"; break;
}
}
}
return 0;
}