diff --git a/openmc/material.py b/openmc/material.py index af42e2e249..9e3951ccf4 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -1449,16 +1449,19 @@ class Materials(cv.CheckedList): for material in self: material.make_isotropic_in_lab() - def _write_xml(self, file): + def _write_xml(self, file, header=True): """Writes XML content of the materials to an open file handle. Parameters ---------- file : IOTextWrapper Open file handle to write content into. + header : bool + Whether or not to write the XML header """ # Write the header and the opening tag for the root element. - file.write("\n") + if header: + file.write("\n") file.write('\n') # Write the element. diff --git a/openmc/model/model.py b/openmc/model/model.py index 5a1b86a1ff..1af3bdffc9 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -444,9 +444,12 @@ class Model: with open(d, 'w', encoding='utf-8', errors='xmlcharrefreplace') as fh: + # write the XML header + fh.write("\n") + fh.write("\n") # Write the materials collection to the open XML file first. # This will write the XML header also - materials._write_xml(fh) + materials._write_xml(fh, False) # Write remaining elements as a tree ET.ElementTree(geometry_element).write(fh, encoding='unicode') ET.ElementTree(settings_element).write(fh, encoding='unicode') @@ -457,6 +460,7 @@ class Model: if self.plots: plots_element = self.plots.to_xml_element() ET.ElementTree(plots_element).write(fh, encoding='unicode') + fh.write("\n") def import_properties(self, filename): """Import physical properties