1

Here is the code but the exported xml appears formatted in a single line.

import xml.etree.ElementTree as ET
import os

sampleXML = """<?xml version="1.0" encoding="ASCII"?>
    <Metadata version="1.0">
        <CODE_OK>510</CODE_OK>
        <DeliveryDate>13/08/2018</DeliveryDate>
    </Metadata>
    """

tree = ET.ElementTree(ET.fromstring(sampleXML))
for folder in os.listdir("YourPath"):         #Iterate the dir
    tree.find("CODE_OK").text = folder        #Update dir name in XML
    tree.write(open(os.path.join(r"Path", folder, "newxml.xml"), "wb")) #Write to XML

Is it possible to either turn this code to something that does exactly what this does and exports it normally formatted

or

to read somehow the exported xml and export it again normally formatted.

Thank you.

  • Please do not post the same [question](https://stackoverflow.com/questions/51707009/exported-xml-isnt-well-formatted-but-appears-in-one-line) again – RobJan Aug 06 '18 at 14:48

0 Answers0