Hi,
I'm trying to save elementtree back into an xml file and it bahaves really strange. I have a function which takes some QTextEdit text arguments (obviously QStrings) and if I save a node property as a QString, it saves the file fine, but if I try to save a node text as a QString it separates each string letter and inserts spaces between them and then makes the file binary instead of text so that I can't even edit it later.
My question is - should all strings be Python strings or they can also be QStrings but I'm doing something wrong? Here's the code extract:
self.tree = ElementTree()
self.xmlDoc = self.tree.parse(self.xmlFile)
self.lstProperty = self.xmlDoc.getiterator("property")
...
def SaveUnits(self, strProperty, strUnit, strNewProperty, strNewUnit):
for property in self.lstProperty:
if property.attrib["name"] == strProperty:
lstUnits = property.getiterator("unit")
for units in lstUnits:
toUnit = units.getchildren()
if toUnit[0].text == strUnit:
toUnit[0].text = str(strNewUnit)
property.attrib["name"] = strNewProperty
self.tree.write(self.xmlFile, "utf-8")
return True
The xml looks fine:
<property name="Property1">
<unit>
<unitname>unit1</unitname>
If I use 'toUnit[0].text = strNewUnit', then it looks like this:
<property name="Property1">
<unit>
<unitname>u n i t 1 </unitname>
Thank you.