diff --git a/include/mapnik/xml_node.hpp b/include/mapnik/xml_node.hpp index 1630460dd..8fd80bc99 100644 --- a/include/mapnik/xml_node.hpp +++ b/include/mapnik/xml_node.hpp @@ -92,6 +92,9 @@ public: void add_attribute(const char * name, const char * value); attribute_map const& get_attributes() const; + bool ignore() const; + void set_ignore(bool ignore) const; + bool processed() const; void set_processed(bool processed) const; @@ -130,6 +133,7 @@ private: bool is_text_; unsigned line_; mutable bool processed_; + mutable bool ignore_; static std::string xml_text; }; diff --git a/src/load_map.cpp b/src/load_map.cpp index eaf985ad2..ce3eaead2 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -540,6 +540,14 @@ void map_parser::parse_layer(Map & map, xml_node const& node) std::string name; try { + optional status = node.get_opt_attr("status"); + + // return early is status is off + if (status && !(*status)){ + node.set_ignore(true); + return; + } + name = node.get_attr("name", std::string("Unnamed")); // If no projection is given inherit from map @@ -555,7 +563,7 @@ void map_parser::parse_layer(Map & map, xml_node const& node) } layer lyr(name, srs); - optional status = node.get_opt_attr("status"); + if (status) { lyr.set_active(* status); @@ -1656,33 +1664,35 @@ void map_parser::find_unused_nodes(xml_node const& root) void map_parser::find_unused_nodes_recursive(xml_node const& node, std::string & error_message) { - if (!node.processed()) + if (!node.ignore()) { - if (node.is_text()) + if (!node.processed()) { - error_message += "\n* text '" + node.text() + "'"; + if (node.is_text()) + { + error_message += "\n* text '" + node.text() + "'"; + } + else + { + error_message += "\n* node '" + node.name() + "' at line " + node.line_to_string(); + } + return; //All attributes and children are automatically unprocessed, too. } - else + xml_node::attribute_map const& attrs = node.get_attributes(); + for (auto const& attr : attrs) { - error_message += "\n* node '" + node.name() + "' at line " + node.line_to_string(); + if (!attr.second.processed) + { + error_message += "\n* attribute '" + attr.first + + "' with value '" + attr.second.value + + "' at line " + node.line_to_string(); + } } - return; //All attributes and children are automatically unprocessed, too. - } - xml_node::attribute_map const& attrs = node.get_attributes(); - for (auto const& attr : attrs) - { - if (!attr.second.processed) + for (auto const& child_node : node) { - error_message += "\n* attribute '" + attr.first + - "' with value '" + attr.second.value + - "' at line " + node.line_to_string(); + find_unused_nodes_recursive(child_node, error_message); } } - - for (auto const& child_node : node) - { - find_unused_nodes_recursive(child_node, error_message); - } } } // end of namespace mapnik diff --git a/src/xml_tree.cpp b/src/xml_tree.cpp index f2f79bb85..0e2caa1c4 100644 --- a/src/xml_tree.cpp +++ b/src/xml_tree.cpp @@ -169,7 +169,8 @@ xml_node::xml_node(xml_tree &tree, std::string && name, unsigned line, bool is_t name_(std::move(name)), is_text_(is_text), line_(line), - processed_(false) {} + processed_(false), + ignore_(false) {} std::string xml_node::xml_text = ""; @@ -244,6 +245,16 @@ bool xml_node::processed() const return processed_; } +void xml_node::set_ignore(bool ignore) const +{ + ignore_ = ignore; +} + +bool xml_node::ignore() const +{ + return ignore_; +} + std::size_t xml_node::size() const { return children_.size();