Skip to content


Subversion checkout URL

You can clone with
Download ZIP

Loading… does not work with None values #742

artemp opened this Issue · 1 comment

2 participants


The following patch solves problem with XML conversion scripts from mapnik1 to mapnik2.

Problem description:
If there are tags with empty values, which should be converted to attributes with empty values, Python will use None as tag value, but it will give error when writing None as attribute value; thus, there must be recursive search for None's from whole XML tree after doing conversion and before writing it to file; all None's must be replaced with empty strings.

Problem example:

<CssParameter name="stroke-dasharray"/>

Here, stroke-dasharray is empty tag, therefore with value None (instead of "").

After (correct) conversion:

<LineSymbolizer stroke-dasharray="" />

Trying to write "" into file will result in error, because only string type is allowed by XML standard and etree class accepts only that type.


+++ b/
@@ -202,7 +202,15 @@ def upgrade(input_xml,output_xml=None,indent_xml=True):

 if indent_xml:


  • def none_to_empty_string_rec(tree):
  • for a in tree.findall('*'):
  • for k, v in a.attrib.items():
  • if v == None:
  • a.attrib[k] = ""
  • none_to_empty_string_rec(a)
  • none_to_empty_string_rec(tree) + if output_xml: tree.write(output_xml) else: }}}

[qtvali] Just forget - as this tool is able to use three different etree classes and I've tested with just one of them ("import xml.etree.ElementTree as etree"), it might be reproducible on all systems; instead of:

import lxml.etree as etree
except ImportError:
import elementtree.ElementTree as etree
except ImportError:
import xml.etree.ElementTree as etree

Simply this should be used for initial testing:

import xml.etree.ElementTree as etree

Otherwise, this bug reproduces on Windows and Linux.

@springmeyer springmeyer closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.