Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8861737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:33:28+00:00 2026-06-14T15:33:28+00:00

I have an XML document called sync_list.xml structured like this: root = ET.Element(root) synced

  • 0

I have an XML document called sync_list.xml structured like this:

root = ET.Element("root")
synced = ET.SubElement(root, "synced")
synced.set("name", "Already Synced")
sfile = ET.SubElement(synced, "sfile")
sfile.set("name", "Filename")
sfile.text = "base"

tree = ET.ElementTree(root)
tree.write("sync_list.xml")

so that I end up with:

<root><synced name="Already Synced"><sfile name="Filename">base</sfile></synced></root>

and I’m multiple files within a directory. I would like to “append” those file names as a new sfile entry each time a file is opened. So I would end up with something like this:

<root><synced name="Already Synced"><sfile name="Filename">base</sfile><sfile name="Filename">File1.blah</sfile><sfile name="Filename">File2.blah</sfile><sfile name="Filename">File3.blah</sfile></synced></root>

How would I achieve this? Thank you so much for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:33:29+00:00Added an answer on June 14, 2026 at 3:33 pm

    You almost there. You just need to read the file back and find the <synced> element in it:

    from __future__ import unicode_literals
    from xml.etree import cElementTree as etree
    
    tree = etree.parse('sync_list.xml')
    synced = tree.find('synced')
    for filename in ["file\u00b9", "file2", "file3"]:
        sfile = etree.SubElement(synced, "sfile", name="Filename")
        sfile.text = filename
    
    tree.write('sync_list_appended.xml', encoding='utf-8', xml_declaration=True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com
I have following scenario: I have a XML-Document, e.g. like this <someRootElement> <tag1> <tag2
Currently, I have an XML document (called Food_Display_Table.xml) with data in a format like
I have an xml (called xdoc) file like the following: <Root> <ItemContainer> <Item> <Item>
I have an XML document with a default namespace indicated at the root. Something
I have an XML document below and there is a tag called <FormData> in
I have an XML file, that contain IDs in an attribute called translatedID. This
I have something similar to the following in an XML document: <variables> <variable> <name>ctrl_btn</name>
I have an XML document that needs to pass text inside an element with
I have a XML document called RESTORE.XML It hold these values.. <EmployeeDetails> <EmployeeID>156824</EmployeeID> <EmployeeName>ALEX</EmployeeName>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.