Xport Interface: markup::attributes
For a derived element
object, retrieves all attribute values, or clears all attributes.
virtual std::map<xhtml_attribute, std::string>* markup::attributes();1st Variety
virtual const std::map<xhtml_attribute, std::string>* markup::attributes()2nd Variety
Parameters
None
Returns
Returns a pointer (or const pointer in the 2nd variety) to the attributes map for a derived element object.
Remarks
This operation is revelant only if it is called on a derived element
object. If called on a pcdata
, comment
,
or procinstr
object, an empty attribute map will be returned.
When called on a derived element
object, a pointer (or const pointer in the 2nd variety) is to the element's attribute map is returned.
In this map, the key type is xhtml_attribute enumerators, and the value type is a string representing the value for the corrasponding attribute.
Complexity
Constant
Example
1st Variety
#include "xhtml_doc.h"
#include "xport_brochure.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
stylesheet ss;
xport_brochure broch;
broch.create(doc, ss);
markup::const_descendant_iterator it = doc.descendant_begin();
for (; it != doc.descendant_end(); ++it) {
if (it->markup_type() == mt_element) {
const std::map<xhtml_attribute, std::string>* attr_map = it->attributes();
if (attr_map->size() > 1) {
std::cout << it->tag_name() << " element has multiple attributes.\n";
}
}
}
return 0;
}
2nd Variety
#include "xhtml_doc.h"
#include "xport_brochure.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
doc.body()->attribute(id, "content_holder");
doc.body()->attribute(attribute::title, "the body");
formatter fmtr(std::cout);
doc.write(fmtr);
doc.body()->attributes()->clear();
std::cout << "\n\n";
doc.write(fmtr);
return 0;
}