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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:23:17+00:00 2026-06-07T22:23:17+00:00

I extracted information from two XML files into 2 dictionaries because I wanted to

  • 0

I extracted information from two XML files into 2 dictionaries because I wanted to compare these files and change information in one of them.

These are my dictionaries:

source dictionary:

d_source={'123': 'description_1', '456': 'description_2'}

target dictionary:

d_target={'123': '\n', '456': 'description_2'}

This is my replacement code:

for i in d_source:
    for j in d_target:
        if d_target[j]=='\n':
            d_target[j]=d_source[i]
print (d_target)

d_target is updated to

d_target = {'123': 'description_1', '456': 'description_2'}

However, my original files from which I extracted the dictionaries remain unchanged. What am I missing here?

  • 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-07T22:23:18+00:00Added an answer on June 7, 2026 at 10:23 pm

    One of the solutions for you would be:

    Let’s say you want to print it as a json, it makes sense if you are already using dicts.

    import json 
    output = json.dumps(d_target)
    
    f = open("myfile", 'w')
    f.write(output)
    f.close()
    

    This will print your dict to file myfile as a json.

    And if you want it as a xml you can use elementtree module.

    Then you could use something like this:

    from elementtree import ElementTree as ETree
    ET = ETree
    ET.xml_declaration = "true"
    products = ET.Element("products")
    properties = ET.Element("properties")
    products.append(properties)
    products.attrib["xmlns"] = "http://schema.example.com/product_data_1.0"
    update = ET.Element("update")
    delete = ET.Element("delete")
    products.append(delete)
    products.append(update)
    

    This is just an example to see how it is done and this would create something like:

     <products xmlns="http://schema.example.com/product_data_1.0">
          <properties />
          <delete />
          <update />
     </products>
    

    And to print this xml to file again:

    output = ET.tostring(products, "utf-8")
    f = open("xml", 'w')
    f.write(output)
    f.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two pieces of information extracted from a MySQL database, the year (2009,
I need to pull RAM information from several cpuz reports and put them into
I have two cases to extract information from the IDataReader object Case - 1
I'm trying to extract two pieces of information from a location. An example location
I need to extract two seperate information from a string. For example, $string =
I've got two tables from which I need to extract information, but the data
I have an xml feed, which i'm attempting to extract two values from. I'll
I want to extract information from Twitter using Python. There is a page with
I need to parse/extract information from an html page. Basically what I'm doing is
I want to extract information from a web page. The page has m nodes,

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.