Dump xml tree.
This commit is contained in:
parent
c3cd50ff57
commit
2a7709a0cf
4 changed files with 26 additions and 10 deletions
|
@ -1,10 +1,10 @@
|
|||
#ifndef DUMP_XML_HPP
|
||||
#define DUMP_XML_HPP
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <mapnik/xml_tree.hpp>
|
||||
|
||||
/* Debug dump ptree XML representation.
|
||||
*/
|
||||
void dump_xml(boost::property_tree::ptree const& xml, unsigned level=0)
|
||||
void dump_xml(xml_node const& xml, unsigned level=0)
|
||||
{
|
||||
std::string indent;
|
||||
int i;
|
||||
|
@ -12,15 +12,23 @@ void dump_xml(boost::property_tree::ptree const& xml, unsigned level=0)
|
|||
{
|
||||
indent += " ";
|
||||
}
|
||||
if (xml.data().length()) std::cout << indent << "data: '" << xml.data() << "'\n";
|
||||
boost::property_tree::ptree::const_iterator itr = xml.begin();
|
||||
boost::property_tree::ptree::const_iterator end = xml.end();
|
||||
xml_node::attribute_map const& attr = xml.get_attributes();
|
||||
std::cout << indent <<"[" << xml.name();
|
||||
xml_node::attribute_map::const_iterator aitr = attr.begin();
|
||||
xml_node::attribute_map::const_iterator aend = attr.end();
|
||||
for (;aitr!=aend; aitr++)
|
||||
{
|
||||
std::cout << " (" << aitr->first << ", " << aitr->second.value << ", " << aitr->second.processed << ")";
|
||||
}
|
||||
std::cout << "]" << "\n";
|
||||
if (xml.is_text()) std::cout << indent << "text: '" << xml.text() << "'\n";
|
||||
xml_node::const_iterator itr = xml.begin();
|
||||
xml_node::const_iterator end = xml.end();
|
||||
for (; itr!=end; itr++)
|
||||
{
|
||||
std::cout << indent <<"[" << itr->first << "]" << "\n";
|
||||
dump_xml(itr->second, level+1);
|
||||
std::cout << indent << "[/" << itr->first << "]" << "\n";
|
||||
dump_xml(*itr, level+1);
|
||||
}
|
||||
std::cout << indent << "[/" << xml.name() << "]" << "\n";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ class xml_node
|
|||
{
|
||||
public:
|
||||
typedef std::list<xml_node>::const_iterator const_iterator;
|
||||
typedef std::map<std::string, xml_attribute> attribute_map;
|
||||
xml_node(xml_tree &tree, std::string name, unsigned line=0, bool text_node = false);
|
||||
|
||||
std::string name() const;
|
||||
|
@ -93,6 +94,7 @@ public:
|
|||
|
||||
xml_node &add_child(std::string const& name, unsigned line=0, bool text_node = false);
|
||||
void add_attribute(std::string const& name, std::string const& value);
|
||||
attribute_map const& get_attributes() const;
|
||||
|
||||
void set_processed(bool processed) const;
|
||||
|
||||
|
@ -120,7 +122,7 @@ private:
|
|||
xml_tree &tree_;
|
||||
std::string name_;
|
||||
std::list<xml_node> children_;
|
||||
std::map<std::string, xml_attribute> attributes_;
|
||||
attribute_map attributes_;
|
||||
bool text_node_;
|
||||
unsigned line_;
|
||||
mutable bool processed_;
|
||||
|
|
|
@ -141,7 +141,7 @@ private:
|
|||
|
||||
};
|
||||
|
||||
|
||||
#include <mapnik/internal/dump_xml.hpp>
|
||||
void load_map(Map & map, std::string const& filename, bool strict)
|
||||
{
|
||||
xml_tree tree;
|
||||
|
@ -161,6 +161,7 @@ void load_map(Map & map, std::string const& filename, bool strict)
|
|||
#endif
|
||||
map_parser parser(strict, filename);
|
||||
parser.parse_map(map, tree.root());
|
||||
dump_xml(tree.root());
|
||||
}
|
||||
|
||||
void load_map_string(Map & map, std::string const& str, bool strict, std::string const& base_path)
|
||||
|
|
|
@ -278,6 +278,11 @@ void xml_node::add_attribute(std::string const& name, std::string const& value)
|
|||
attributes_.insert(std::make_pair(name,xml_attribute(value)));
|
||||
}
|
||||
|
||||
xml_node::attribute_map const& xml_node::get_attributes() const
|
||||
{
|
||||
return attributes_;
|
||||
}
|
||||
|
||||
void xml_node::set_processed(bool processed) const
|
||||
{
|
||||
processed_ = processed;
|
||||
|
|
Loading…
Add table
Reference in a new issue