Xport Interface: element::styles
Retrieves all style values in the called element's
style attribute.
virtual std::map<css_property, std::string>* element::styles();1st Variety
virtual const std::map<css_property, std::string>* element::styles() const;2nd Variety
Parameters
none
Returns
Returns a pointer (or const pointer in the 2nd variety) to the element's style map, which includes the css property/value pairs for all css properties
set in the style attribute for the called element
.
Remarks
Returns a pointer (or const pointer in the 2nd variety) to the element's style map.
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) {
const 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;
}