XmlMaterialProfile.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. # Copyright (c) 2016 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. import math
  4. import copy
  5. import io
  6. import xml.etree.ElementTree as ET
  7. import uuid
  8. from UM.Resources import Resources
  9. from UM.Logger import Logger
  10. from UM.Util import parseBool
  11. from cura.CuraApplication import CuraApplication
  12. import UM.Dictionary
  13. import UM.Settings
  14. ## Handles serializing and deserializing material containers from an XML file
  15. class XmlMaterialProfile(UM.Settings.InstanceContainer):
  16. def __init__(self, container_id, *args, **kwargs):
  17. super().__init__(container_id, *args, **kwargs)
  18. self._inherited_files = []
  19. def getInheritedFiles(self):
  20. return self._inherited_files
  21. ## Overridden from InstanceContainer
  22. def setReadOnly(self, read_only):
  23. super().setReadOnly(read_only)
  24. basefile = self.getMetaDataEntry("base_file", self._id) # if basefile is self.id, this is a basefile.
  25. for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
  26. container._read_only = read_only # prevent loop instead of calling setReadOnly
  27. ## Overridden from InstanceContainer
  28. # set the meta data for all machine / variant combinations
  29. def setMetaDataEntry(self, key, value):
  30. if self.isReadOnly():
  31. return
  32. if self.getMetaDataEntry(key, None) == value:
  33. # Prevent loop caused by for loop.
  34. return
  35. super().setMetaDataEntry(key, value)
  36. basefile = self.getMetaDataEntry("base_file", self._id) #if basefile is self.id, this is a basefile.
  37. # Update all containers that share GUID and basefile
  38. for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
  39. container.setMetaDataEntry(key, value)
  40. ## Overridden from InstanceContainer, similar to setMetaDataEntry.
  41. # without this function the setName would only set the name of the specific nozzle / material / machine combination container
  42. # The function is a bit tricky. It will not set the name of all containers if it has the correct name itself.
  43. def setName(self, new_name):
  44. if self.isReadOnly():
  45. return
  46. # Not only is this faster, it also prevents a major loop that causes a stack overflow.
  47. if self.getName() == new_name:
  48. return
  49. super().setName(new_name)
  50. basefile = self.getMetaDataEntry("base_file", self._id) # if basefile is self.id, this is a basefile.
  51. # Update the basefile as well, this is actually what we're trying to do
  52. # Update all containers that share GUID and basefile
  53. containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile)
  54. for container in containers:
  55. container.setName(new_name)
  56. ## Overridden from InstanceContainer
  57. # def setProperty(self, key, property_name, property_value, container = None):
  58. # if self.isReadOnly():
  59. # return
  60. #
  61. # super().setProperty(key, property_name, property_value)
  62. #
  63. # basefile = self.getMetaDataEntry("base_file", self._id) #if basefile is self.id, this is a basefile.
  64. # for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
  65. # if not container.isReadOnly():
  66. # container.setDirty(True)
  67. ## Overridden from InstanceContainer
  68. # base file: global settings + supported machines
  69. # machine / variant combination: only changes for itself.
  70. def serialize(self):
  71. registry = UM.Settings.ContainerRegistry.getInstance()
  72. base_file = self.getMetaDataEntry("base_file", "")
  73. if base_file and self.id != base_file:
  74. # Since we create an instance of XmlMaterialProfile for each machine and nozzle in the profile,
  75. # we should only serialize the "base" material definition, since that can then take care of
  76. # serializing the machine/nozzle specific profiles.
  77. raise NotImplementedError("Ignoring serializing non-root XML materials, the data is contained in the base material")
  78. builder = ET.TreeBuilder()
  79. root = builder.start("fdmmaterial", { "xmlns": "http://www.ultimaker.com/material"})
  80. ## Begin Metadata Block
  81. builder.start("metadata")
  82. metadata = copy.deepcopy(self.getMetaData())
  83. properties = metadata.pop("properties", {})
  84. # Metadata properties that should not be serialized.
  85. metadata.pop("status", "")
  86. metadata.pop("variant", "")
  87. metadata.pop("type", "")
  88. metadata.pop("base_file", "")
  89. ## Begin Name Block
  90. builder.start("name")
  91. builder.start("brand")
  92. builder.data(metadata.pop("brand", ""))
  93. builder.end("brand")
  94. builder.start("material")
  95. builder.data(metadata.pop("material", ""))
  96. builder.end("material")
  97. builder.start("color")
  98. builder.data(metadata.pop("color_name", ""))
  99. builder.end("color")
  100. builder.start("label")
  101. builder.data(self._name)
  102. builder.end("label")
  103. builder.end("name")
  104. ## End Name Block
  105. for key, value in metadata.items():
  106. builder.start(key)
  107. # Normally value is a string.
  108. # Nones get handled well.
  109. if isinstance(value, bool):
  110. value = str(value) # parseBool in deserialize expects 'True'.
  111. builder.data(value)
  112. builder.end(key)
  113. builder.end("metadata")
  114. ## End Metadata Block
  115. ## Begin Properties Block
  116. builder.start("properties")
  117. for key, value in properties.items():
  118. builder.start(key)
  119. builder.data(value)
  120. builder.end(key)
  121. builder.end("properties")
  122. ## End Properties Block
  123. ## Begin Settings Block
  124. builder.start("settings")
  125. if self.getDefinition().id == "fdmprinter":
  126. for instance in self.findInstances():
  127. self._addSettingElement(builder, instance)
  128. machine_container_map = {}
  129. machine_nozzle_map = {}
  130. all_containers = registry.findInstanceContainers(GUID = self.getMetaDataEntry("GUID"), base_file = self._id)
  131. for container in all_containers:
  132. definition_id = container.getDefinition().id
  133. if definition_id == "fdmprinter":
  134. continue
  135. if definition_id not in machine_container_map:
  136. machine_container_map[definition_id] = container
  137. if definition_id not in machine_nozzle_map:
  138. machine_nozzle_map[definition_id] = {}
  139. variant = container.getMetaDataEntry("variant")
  140. if variant:
  141. machine_nozzle_map[definition_id][variant] = container
  142. continue
  143. machine_container_map[definition_id] = container
  144. for definition_id, container in machine_container_map.items():
  145. definition = container.getDefinition()
  146. try:
  147. product = UM.Dictionary.findKey(self.__product_id_map, definition_id)
  148. except ValueError:
  149. # An unknown product id; export it anyway
  150. product = definition_id
  151. builder.start("machine")
  152. builder.start("machine_identifier", { "manufacturer": definition.getMetaDataEntry("manufacturer", ""), "product": product})
  153. builder.end("machine_identifier")
  154. for instance in container.findInstances():
  155. if self.getDefinition().id == "fdmprinter" and self.getInstance(instance.definition.key) and self.getProperty(instance.definition.key, "value") == instance.value:
  156. # If the settings match that of the base profile, just skip since we inherit the base profile.
  157. continue
  158. self._addSettingElement(builder, instance)
  159. # Find all hotend sub-profiles corresponding to this material and machine and add them to this profile.
  160. for hotend_id, hotend in machine_nozzle_map[definition_id].items():
  161. variant_containers = registry.findInstanceContainers(id = hotend.getMetaDataEntry("variant"))
  162. if not variant_containers:
  163. continue
  164. builder.start("hotend", {"id": variant_containers[0].getName()})
  165. # Compatible is a special case, as it's added as a meta data entry (instead of an instance).
  166. compatible = hotend.getMetaDataEntry("compatible")
  167. if compatible is not None:
  168. builder.start("setting", {"key": "hardware compatible"})
  169. if compatible:
  170. builder.data("yes")
  171. else:
  172. builder.data("no")
  173. builder.end("setting")
  174. for instance in hotend.findInstances():
  175. if container.getInstance(instance.definition.key) and container.getProperty(instance.definition.key, "value") == instance.value:
  176. # If the settings match that of the machine profile, just skip since we inherit the machine profile.
  177. continue
  178. self._addSettingElement(builder, instance)
  179. builder.end("hotend")
  180. builder.end("machine")
  181. builder.end("settings")
  182. ## End Settings Block
  183. builder.end("fdmmaterial")
  184. root = builder.close()
  185. _indent(root)
  186. stream = io.StringIO()
  187. tree = ET.ElementTree(root)
  188. tree.write(stream, encoding="unicode", xml_declaration=True)
  189. return stream.getvalue()
  190. # Recursively resolve loading inherited files
  191. def _resolveInheritance(self, file_name):
  192. xml = self._loadFile(file_name)
  193. inherits = xml.find("./um:inherits", self.__namespaces)
  194. if inherits is not None:
  195. inherited = self._resolveInheritance(inherits.text)
  196. xml = self._mergeXML(inherited, xml)
  197. return xml
  198. def _loadFile(self, file_name):
  199. path = Resources.getPath(CuraApplication.getInstance().ResourceTypes.MaterialInstanceContainer, file_name + ".xml.fdm_material")
  200. with open(path, encoding="utf-8") as f:
  201. contents = f.read()
  202. self._inherited_files.append(path)
  203. return ET.fromstring(contents)
  204. # The XML material profile can have specific settings for machines.
  205. # Some machines share profiles, so they are only created once.
  206. # This function duplicates those elements so that each machine tag only has one identifier.
  207. def _expandMachinesXML(self, element):
  208. settings_element = element.find("./um:settings", self.__namespaces)
  209. machines = settings_element.iterfind("./um:machine", self.__namespaces)
  210. machines_to_add = []
  211. machines_to_remove = []
  212. for machine in machines:
  213. identifiers = list(machine.iterfind("./um:machine_identifier", self.__namespaces))
  214. has_multiple_identifiers = len(identifiers) > 1
  215. if has_multiple_identifiers:
  216. # Multiple identifiers found. We need to create a new machine element and copy all it's settings there.
  217. for identifier in identifiers:
  218. new_machine = copy.deepcopy(machine)
  219. # Create list of identifiers that need to be removed from the copied element.
  220. other_identifiers = [self._createKey(other_identifier) for other_identifier in identifiers if other_identifier is not identifier]
  221. # As we can only remove by exact object reference, we need to look through the identifiers of copied machine.
  222. new_machine_identifiers = list(new_machine.iterfind("./um:machine_identifier", self.__namespaces))
  223. for new_machine_identifier in new_machine_identifiers:
  224. key = self._createKey(new_machine_identifier)
  225. # Key was in identifiers to remove, so this element needs to be purged
  226. if key in other_identifiers:
  227. new_machine.remove(new_machine_identifier)
  228. machines_to_add.append(new_machine)
  229. machines_to_remove.append(machine)
  230. else:
  231. pass # Machine only has one identifier. Nothing to do.
  232. # Remove & add all required machines.
  233. for machine_to_remove in machines_to_remove:
  234. settings_element.remove(machine_to_remove)
  235. for machine_to_add in machines_to_add:
  236. settings_element.append(machine_to_add)
  237. return element
  238. def _mergeXML(self, first, second):
  239. result = copy.deepcopy(first)
  240. self._combineElement(self._expandMachinesXML(result), self._expandMachinesXML(second))
  241. return result
  242. def _createKey(self, element):
  243. key = element.tag.split("}")[-1]
  244. if "key" in element.attrib:
  245. key += " key:" + element.attrib["key"]
  246. if "manufacturer" in element.attrib:
  247. key += " manufacturer:" + element.attrib["manufacturer"]
  248. if "product" in element.attrib:
  249. key += " product:" + element.attrib["product"]
  250. if key == "machine":
  251. for item in element:
  252. if "machine_identifier" in item.tag:
  253. key += " " + item.attrib["product"]
  254. return key
  255. # Recursively merges XML elements. Updates either the text or children if another element is found in first.
  256. # If it does not exist, copies it from second.
  257. def _combineElement(self, first, second):
  258. # Create a mapping from tag name to element.
  259. mapping = {}
  260. for element in first:
  261. key = self._createKey(element)
  262. mapping[key] = element
  263. for element in second:
  264. key = self._createKey(element)
  265. if len(element): # Check if element has children.
  266. try:
  267. if "setting" in element.tag and not "settings" in element.tag:
  268. # Setting can have points in it. In that case, delete all values and override them.
  269. for child in list(mapping[key]):
  270. mapping[key].remove(child)
  271. for child in element:
  272. mapping[key].append(child)
  273. else:
  274. self._combineElement(mapping[key], element) # Multiple elements, handle those.
  275. except KeyError:
  276. mapping[key] = element
  277. first.append(element)
  278. else:
  279. try:
  280. mapping[key].text = element.text
  281. except KeyError: # Not in the mapping, so simply add it
  282. mapping[key] = element
  283. first.append(element)
  284. def clearData(self):
  285. self._metadata = {}
  286. self._name = ""
  287. self._definition = None
  288. self._instances = {}
  289. self._read_only = False
  290. self._dirty = False
  291. self._path = ""
  292. ## Overridden from InstanceContainer
  293. def deserialize(self, serialized):
  294. data = ET.fromstring(serialized)
  295. # Reset previous metadata
  296. self.clearData() # Ensure any previous data is gone.
  297. self.addMetaDataEntry("type", "material")
  298. self.addMetaDataEntry("base_file", self.id)
  299. # TODO: Add material verfication
  300. self.addMetaDataEntry("status", "unknown")
  301. inherits = data.find("./um:inherits", self.__namespaces)
  302. if inherits is not None:
  303. inherited = self._resolveInheritance(inherits.text)
  304. data = self._mergeXML(inherited, data)
  305. metadata = data.iterfind("./um:metadata/*", self.__namespaces)
  306. for entry in metadata:
  307. tag_name = _tag_without_namespace(entry)
  308. if tag_name == "name":
  309. brand = entry.find("./um:brand", self.__namespaces)
  310. material = entry.find("./um:material", self.__namespaces)
  311. color = entry.find("./um:color", self.__namespaces)
  312. label = entry.find("./um:label", self.__namespaces)
  313. if label is not None:
  314. self.setName(label.text)
  315. else:
  316. self.setName(self._profile_name(material.text, color.text))
  317. self.addMetaDataEntry("brand", brand.text)
  318. self.addMetaDataEntry("material", material.text)
  319. self.addMetaDataEntry("color_name", color.text)
  320. continue
  321. self.addMetaDataEntry(tag_name, entry.text)
  322. if not "description" in self.getMetaData():
  323. self.addMetaDataEntry("description", "")
  324. if not "adhesion_info" in self.getMetaData():
  325. self.addMetaDataEntry("adhesion_info", "")
  326. property_values = {}
  327. properties = data.iterfind("./um:properties/*", self.__namespaces)
  328. for entry in properties:
  329. tag_name = _tag_without_namespace(entry)
  330. property_values[tag_name] = entry.text
  331. diameter = float(property_values.get("diameter", 2.85)) # In mm
  332. density = float(property_values.get("density", 1.3)) # In g/cm3
  333. self.addMetaDataEntry("properties", property_values)
  334. self.setDefinition(UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0])
  335. global_compatibility = True
  336. global_setting_values = {}
  337. settings = data.iterfind("./um:settings/um:setting", self.__namespaces)
  338. for entry in settings:
  339. key = entry.get("key")
  340. if key in self.__material_property_setting_map:
  341. self.setProperty(self.__material_property_setting_map[key], "value", entry.text)
  342. global_setting_values[self.__material_property_setting_map[key]] = entry.text
  343. elif key in self.__unmapped_settings:
  344. if key == "hardware compatible":
  345. global_compatibility = parseBool(entry.text)
  346. else:
  347. Logger.log("d", "Unsupported material setting %s", key)
  348. self.addMetaDataEntry("compatible", global_compatibility)
  349. self._dirty = False
  350. machines = data.iterfind("./um:settings/um:machine", self.__namespaces)
  351. for machine in machines:
  352. machine_compatibility = global_compatibility
  353. machine_setting_values = {}
  354. settings = machine.iterfind("./um:setting", self.__namespaces)
  355. for entry in settings:
  356. key = entry.get("key")
  357. if key in self.__material_property_setting_map:
  358. machine_setting_values[self.__material_property_setting_map[key]] = entry.text
  359. elif key in self.__unmapped_settings:
  360. if key == "hardware compatible":
  361. machine_compatibility = parseBool(entry.text)
  362. else:
  363. Logger.log("d", "Unsupported material setting %s", key)
  364. identifiers = machine.iterfind("./um:machine_identifier", self.__namespaces)
  365. for identifier in identifiers:
  366. machine_id = self.__product_id_map.get(identifier.get("product"), None)
  367. if machine_id is None:
  368. # Lets try again with some naive heuristics.
  369. machine_id = identifier.get("product").replace(" ", "").lower()
  370. definitions = UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id = machine_id)
  371. if not definitions:
  372. Logger.log("w", "No definition found for machine ID %s", machine_id)
  373. continue
  374. definition = definitions[0]
  375. if machine_compatibility:
  376. new_material_id = self.id + "_" + machine_id
  377. # It could be that we are overwriting, so check if the ID already exists.
  378. materials = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=new_material_id)
  379. if materials:
  380. new_material = materials[0]
  381. new_material.clearData()
  382. else:
  383. new_material = XmlMaterialProfile(new_material_id)
  384. new_material.setName(self.getName())
  385. new_material.setMetaData(copy.deepcopy(self.getMetaData()))
  386. new_material.setDefinition(definition)
  387. # Don't use setMetadata, as that overrides it for all materials with same base file
  388. new_material.getMetaData()["compatible"] = machine_compatibility
  389. for key, value in global_setting_values.items():
  390. new_material.setProperty(key, "value", value)
  391. for key, value in machine_setting_values.items():
  392. new_material.setProperty(key, "value", value)
  393. new_material._dirty = False
  394. if not materials:
  395. UM.Settings.ContainerRegistry.getInstance().addContainer(new_material)
  396. hotends = machine.iterfind("./um:hotend", self.__namespaces)
  397. for hotend in hotends:
  398. hotend_id = hotend.get("id")
  399. if hotend_id is None:
  400. continue
  401. variant_containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = hotend_id)
  402. if not variant_containers:
  403. # It is not really properly defined what "ID" is so also search for variants by name.
  404. variant_containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(definition = definition.id, name = hotend_id)
  405. if not variant_containers:
  406. Logger.log("d", "No variants found with ID or name %s for machine %s", hotend_id, definition.id)
  407. continue
  408. hotend_compatibility = machine_compatibility
  409. hotend_setting_values = {}
  410. settings = hotend.iterfind("./um:setting", self.__namespaces)
  411. for entry in settings:
  412. key = entry.get("key")
  413. if key in self.__material_property_setting_map:
  414. hotend_setting_values[self.__material_property_setting_map[key]] = entry.text
  415. elif key in self.__unmapped_settings:
  416. if key == "hardware compatible":
  417. hotend_compatibility = parseBool(entry.text)
  418. else:
  419. Logger.log("d", "Unsupported material setting %s", key)
  420. # It could be that we are overwriting, so check if the ID already exists.
  421. new_hotend_id = self.id + "_" + machine_id + "_" + hotend_id.replace(" ", "_")
  422. materials = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=new_hotend_id)
  423. if materials:
  424. new_hotend_material = materials[0]
  425. new_hotend_material.clearData()
  426. else:
  427. new_hotend_material = XmlMaterialProfile(new_hotend_id)
  428. new_hotend_material.setName(self.getName())
  429. new_hotend_material.setMetaData(copy.deepcopy(self.getMetaData()))
  430. new_hotend_material.setDefinition(definition)
  431. new_hotend_material.addMetaDataEntry("variant", variant_containers[0].id)
  432. # Don't use setMetadata, as that overrides it for all materials with same base file
  433. new_hotend_material.getMetaData()["compatible"] = hotend_compatibility
  434. for key, value in global_setting_values.items():
  435. new_hotend_material.setProperty(key, "value", value)
  436. for key, value in machine_setting_values.items():
  437. new_hotend_material.setProperty(key, "value", value)
  438. for key, value in hotend_setting_values.items():
  439. new_hotend_material.setProperty(key, "value", value)
  440. new_hotend_material._dirty = False
  441. if not materials: # It was not added yet, do so now.
  442. UM.Settings.ContainerRegistry.getInstance().addContainer(new_hotend_material)
  443. def _addSettingElement(self, builder, instance):
  444. try:
  445. key = UM.Dictionary.findKey(self.__material_property_setting_map, instance.definition.key)
  446. except ValueError:
  447. return
  448. builder.start("setting", { "key": key })
  449. builder.data(str(instance.value))
  450. builder.end("setting")
  451. def _profile_name(self, material_name, color_name):
  452. if color_name != "Generic":
  453. return "%s %s" % (color_name, material_name)
  454. else:
  455. return material_name
  456. # Map XML file setting names to internal names
  457. __material_property_setting_map = {
  458. "print temperature": "default_material_print_temperature",
  459. "heated bed temperature": "material_bed_temperature",
  460. "standby temperature": "material_standby_temperature",
  461. "processing temperature graph": "material_flow_temp_graph",
  462. "print cooling": "cool_fan_speed",
  463. "retraction amount": "retraction_amount",
  464. "retraction speed": "retraction_speed"
  465. }
  466. __unmapped_settings = [
  467. "hardware compatible"
  468. ]
  469. # Map XML file product names to internal ids
  470. # TODO: Move this to definition's metadata
  471. __product_id_map = {
  472. "Ultimaker 2": "ultimaker2",
  473. "Ultimaker 2+": "ultimaker2_plus",
  474. "Ultimaker 2 Go": "ultimaker2_go",
  475. "Ultimaker 2 Extended": "ultimaker2_extended",
  476. "Ultimaker 2 Extended+": "ultimaker2_extended_plus",
  477. "Ultimaker Original": "ultimaker_original",
  478. "Ultimaker Original+": "ultimaker_original_plus"
  479. }
  480. # Map of recognised namespaces with a proper prefix.
  481. __namespaces = {
  482. "um": "http://www.ultimaker.com/material"
  483. }
  484. ## Helper function for pretty-printing XML because ETree is stupid
  485. def _indent(elem, level = 0):
  486. i = "\n" + level * " "
  487. if len(elem):
  488. if not elem.text or not elem.text.strip():
  489. elem.text = i + " "
  490. if not elem.tail or not elem.tail.strip():
  491. elem.tail = i
  492. for elem in elem:
  493. _indent(elem, level + 1)
  494. if not elem.tail or not elem.tail.strip():
  495. elem.tail = i
  496. else:
  497. if level and (not elem.tail or not elem.tail.strip()):
  498. elem.tail = i
  499. # The namespace is prepended to the tag name but between {}.
  500. # We are only interested in the actual tag name, so discard everything
  501. # before the last }
  502. def _tag_without_namespace(element):
  503. return element.tag[element.tag.rfind("}") + 1:]