0

I am using dicttoxml to write a dictionary structure to an xml file.

For example

from dicttoxml import dicttoxml
myDict= {"This is a key": "some value"}
myRecord= dicttoxml(myDict, attr_type=False, root=False)

When checking the output file 'This is a key' and the value got converted into

<This_is_a_key>some value</This_is_a_key>

Is there a way to avoid the conversion to underscore so instead I get

<This is a key>some value</This is a key>

hem
  • 1,012
  • 6
  • 11
MaryT
  • 33
  • 4
  • 1
    Why? If it did that, it wouldn't be valid xml. – Jeff Mercado Jul 03 '19 at 15:52
  • This would produce invalid XML. Why? – David Zemens Jul 03 '19 at 15:52
  • with this attempt `` - any of `is`, `a` or `key` could be perceived as attributes. This is incorrect and should not be viable – RomanPerekhrest Jul 03 '19 at 15:53
  • Agreed - in this case I just need to output it this way because of another system requiring column headers that maintain the original key. Not ideal I know. I probably will look into avoiding the xml route completely and instead write into a csv file directly. Thanks for the comments! – MaryT Jul 03 '19 at 17:05

0 Answers0