I want to edit a Story .xml file inside a .idml file in Python

57 Views Asked by At

For context I converted a .indd file to .idml so I could make edits on the template, I originally turned the .idml file to .zip and then extracted it to reveal the .xml files I'd need to edit to change the content of my templates, but re-zipping is a hassle and I wanted it to be able to be done via code.

Here's a screenshot of the file I want to edit, in it I want to edit "Mike O Reilley" to "Jane Doe": Screenshot of the .xml file I wish to edit

I tried writing code in SimpleIDML to write on this field, I managed to view the contents of the .xml itself, but was not able to write back to the same .idml file, the code looks as follows:

import xml.dom.minidom


idml_path = "file.idml"


idml_package = idml.IDMLPackage(idml_path)


stories = idml_package.stories

target_story = "Stories/Story_u13de.xml"

if target_story in stories:
    with idml_package.open(target_story) as f:
        content = f.read()

        dom = xml.dom.minidom.parseString(content)
        pretty_content = dom.toprettyxml(indent="  ") 
        print(pretty_content)
else:
    print(f"Error: {target_story} not found in the IDML package.")

How do I write back to the .idml file with SimpleIDML? Or do you guys have any other alternatives let me know.

0

There are 0 best solutions below