Enable XML parser to return multiple <xmltext> nodes.
This commit is contained in:
parent
e177cd52a7
commit
533b95f0e6
3 changed files with 26 additions and 9 deletions
|
@ -258,7 +258,7 @@ T get(const boost::property_tree::ptree & node, const std::string & name, bool i
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
str = node.get_optional<std::string>(name );
|
str = node.get_optional<std::string>(name+".<xmltext>");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( str ) {
|
if ( str ) {
|
||||||
|
@ -289,7 +289,7 @@ inline color get(boost::property_tree::ptree const& node, std::string const& nam
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
str = node.get_optional<std::string>(name );
|
str = node.get_optional<std::string>(name+".<xmltext>");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( str )
|
if ( str )
|
||||||
|
@ -322,7 +322,7 @@ T get(const boost::property_tree::ptree & node, const std::string & name, bool i
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
str = node.get_optional<std::string>(name);
|
str = node.get_optional<std::string>(name+".<xmltext>");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! str ) {
|
if ( ! str ) {
|
||||||
|
@ -348,7 +348,18 @@ T get_value(const boost::property_tree::ptree & node, const std::string & name)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return node.get_value<T>();
|
/* NOTE: get_child works as long as there is only one child with that name.
|
||||||
|
If this function is used this used this condition must always be satisfied.
|
||||||
|
*/
|
||||||
|
return node.get_child("<xmltext>").get_value<T>();
|
||||||
|
}
|
||||||
|
catch (boost::property_tree::ptree_bad_path)
|
||||||
|
{
|
||||||
|
/* If the XML parser did not find any non-empty data element the is no
|
||||||
|
<xmltext> node. But we don't want to fail here but simply return a
|
||||||
|
default constructed value of the requested type.
|
||||||
|
*/
|
||||||
|
return T();
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
@ -369,7 +380,7 @@ boost::optional<T> get_optional(const boost::property_tree::ptree & node, const
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
str = node.get_optional<std::string>(name);
|
str = node.get_optional<std::string>(name+".<xmltext>");
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<T> result;
|
boost::optional<T> result;
|
||||||
|
@ -403,7 +414,7 @@ inline boost::optional<color> get_optional(const boost::property_tree::ptree & n
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
str = node.get_optional<std::string>(name);
|
str = node.get_optional<std::string>(name+".<xmltext>");
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<color> result;
|
boost::optional<color> result;
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <boost/utility.hpp>
|
#include <boost/utility.hpp>
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <boost/filesystem/operations.hpp>
|
#include <boost/filesystem/operations.hpp>
|
||||||
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
|
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
|
@ -200,8 +201,13 @@ private:
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XML_TEXT_NODE:
|
case XML_TEXT_NODE:
|
||||||
pt.put_value( (char*) cur_node->content );
|
{
|
||||||
break;
|
std::string trimmed = boost::algorithm::trim_copy(std::string((char*)cur_node->content));
|
||||||
|
if (trimmed.empty()) break;
|
||||||
|
ptree::iterator it = pt.push_back(ptree::value_type("<xmltext>", ptree()));
|
||||||
|
it->second.put_value(trimmed);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case XML_COMMENT_NODE:
|
case XML_COMMENT_NODE:
|
||||||
{
|
{
|
||||||
ptree::iterator it = pt.push_back(
|
ptree::iterator it = pt.push_back(
|
||||||
|
|
|
@ -652,7 +652,7 @@ void map_parser::parse_layer( Map & map, ptree const & lay )
|
||||||
if (child.first == "StyleName")
|
if (child.first == "StyleName")
|
||||||
{
|
{
|
||||||
ensure_attrs(child.second, "StyleName", "none");
|
ensure_attrs(child.second, "StyleName", "none");
|
||||||
std::string style_name = child.second.data();
|
std::string style_name = get_value<std::string>(child.second, "style name");
|
||||||
if (style_name.empty())
|
if (style_name.empty())
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
|
|
Loading…
Add table
Reference in a new issue