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 6050569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:42:11+00:00 2026-05-23T07:42:11+00:00

I have xml data in string format which is in variable xml_data xml_data=<?xml version=1.0?>

  • 0

I have xml data in string format which is in variable xml_data

xml_data="<?xml version="1.0"?>
<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>"

I want to save this data to a new xml file through python.

I am using this code:

from xml.etree import ElementTree as ET
tree = ET.XML(xml_data)

Now Here i want to create a xml file and save the xml tree to the file, but don’t know which function to use for this.

Thanks

  • 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-05-23T07:42:12+00:00Added an answer on May 23, 2026 at 7:42 am

    With ET.tostring(tree) you get a non-formatted string representation of the XML. To save it to a file:

    with open("filename", "w") as f:
        f.write(ET.tostring(tree))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel worksheet in XML format which contains <Cell ss:StyleID=s127><Data ss:Type=String>Replace Me</Data></Cell>
Say I have a Java String which has xml data like so: String content
I have an XML string which is output from a Visual Fox Pro based
I have a single xml document (data.xml), which I display as HTML using an
I have an object which I serialize nicely into this: <?xml version=1.0 encoding=utf-8 ?>
I have a CSV string that is embedded within an XML document, which is
I want to display the data from xml to html via jquery I have
I am trying to create an XML file using string data. (Which is itself
We have a string field which can contain XML or plain text. The XML
I have an XML string which contains Dates formatted dd/MM/yyyy hh:mm:ss. I'm loading this

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.