add xinclude support for libxml2 based parser - thanks oldtopos - closes #567

This commit is contained in:
Dane Springmeyer 2010-08-10 06:01:16 +00:00
parent 787374d1b7
commit 6da5983e94
4 changed files with 37 additions and 11 deletions

View file

@ -14,6 +14,8 @@ For a complete change history, see the SVN log.
Mapnik Trunk
------------
- Added xinclude (http://www.w3.org/TR/xinclude/) support to libxml2-based xml parser (oldtopos) (#567)
- Optimized rendering speeds by avoiding locking in the projection code (r2063)
- Added support for setting global alignment of polygon pattern fills (#203)

View file

@ -33,6 +33,7 @@
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/parserInternals.h>
#include <libxml/xinclude.h>
#include <iostream>
@ -147,8 +148,18 @@ public:
throw config_error(os.str());
}
int iXIncludeReturn = xmlXIncludeProcessFlags( doc, options_ );
if (iXIncludeReturn < 0)
{
xmlFreeDoc(doc);
throw config_error("XML XInclude error. One or more files failed to load.");
}
xmlNode * root = xmlDocGetRootElement( doc );
if ( ! root ) {
xmlFreeDoc(doc);
throw config_error("XML document is empty.");
}

View file

@ -83,6 +83,7 @@ public:
void parse_map(Map & map, ptree const & sty);
private:
void parse_map_include( Map & map, ptree const & include);
void parse_style(Map & map, ptree const & sty);
void parse_layer(Map & map, ptree const & lay);
void parse_metawriter(Map & map, ptree const & lay);
@ -190,8 +191,8 @@ void map_parser::parse_map( Map & map, ptree const & pt )
map.set_buffer_size(*buffer_size);
}
// Check if relative paths should be interpreted as relative to/from XML location
// Default is true, and map_parser::ensure_relative_to_xml will be called to modify path
// Check if relative paths should be interpreted as relative to/from XML location
// Default is true, and map_parser::ensure_relative_to_xml will be called to modify path
optional<boolean> paths_from_xml = get_opt_attr<boolean>(map_node, "paths_from_xml");
if (paths_from_xml)
{
@ -243,15 +244,29 @@ void map_parser::parse_map( Map & map, ptree const & pt )
ex.append_context("(in node Map)");
throw;
}
ptree::const_iterator itr = map_node.begin();
ptree::const_iterator end = map_node.end();
parse_map_include( map, map_node );
}
catch (const boost::property_tree::ptree_bad_path &)
{
throw config_error("Not a map file. Node 'Map' not found.");
}
}
void map_parser::parse_map_include( Map & map, ptree const & include )
{
ptree::const_iterator itr = include.begin();
ptree::const_iterator end = include.end();
for (; itr != end; ++itr)
{
ptree::value_type const& v = *itr;
if (v.first == "Style")
if (v.first == "Include")
{
parse_map_include( map, v.second );
}
else if (v.first == "Style")
{
parse_style( map, v.second );
}
@ -307,11 +322,8 @@ void map_parser::parse_map( Map & map, ptree const & pt )
v.first + "'");
}
}
}
catch (const boost::property_tree::ptree_bad_path &)
{
throw config_error("Not a map file. Node 'Map' not found.");
}
map.init_metawriters();
}

View file

@ -45,6 +45,7 @@ if __name__ == "__main__":
xml = sys.argv[1]
tree = objectify.parse(xml)
tree.xinclude()
root = tree.getroot()
# rename 'bgcolor' to 'background-color'