From 2a7709a0cf4bada065ca1dd76ef1ec16ce3119d0 Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Thu, 8 Mar 2012 01:29:19 +0100 Subject: [PATCH] Dump xml tree. --- include/mapnik/internal/dump_xml.hpp | 24 ++++++++++++++++-------- include/mapnik/xml_tree.hpp | 4 +++- src/load_map.cpp | 3 ++- src/xml_tree.cpp | 5 +++++ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/include/mapnik/internal/dump_xml.hpp b/include/mapnik/internal/dump_xml.hpp index 022591f7a..944be73ba 100644 --- a/include/mapnik/internal/dump_xml.hpp +++ b/include/mapnik/internal/dump_xml.hpp @@ -1,10 +1,10 @@ #ifndef DUMP_XML_HPP #define DUMP_XML_HPP -#include +#include /* 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"; } diff --git a/include/mapnik/xml_tree.hpp b/include/mapnik/xml_tree.hpp index 40406382c..b1b750b97 100644 --- a/include/mapnik/xml_tree.hpp +++ b/include/mapnik/xml_tree.hpp @@ -84,6 +84,7 @@ class xml_node { public: typedef std::list::const_iterator const_iterator; + typedef std::map 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 children_; - std::map attributes_; + attribute_map attributes_; bool text_node_; unsigned line_; mutable bool processed_; diff --git a/src/load_map.cpp b/src/load_map.cpp index 6120d22c7..6c6edc281 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -141,7 +141,7 @@ private: }; - +#include 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) diff --git a/src/xml_tree.cpp b/src/xml_tree.cpp index 2ba5ff709..a7714e057 100644 --- a/src/xml_tree.cpp +++ b/src/xml_tree.cpp @@ -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;