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

  • Home
  • SEARCH
  • 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 8497673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:11:36+00:00 2026-06-11T00:11:36+00:00

I have a XML document data.xml: I need to write python script which can

  • 0

I have a XML document “data.xml”:
I need to write python script which can replace all the value nodes with tag ‘Num’ with the new numbers and write it back to the disk.
the difference is that the new value is not string, but a series of continous increasing number, like 1000,1100,1200,1300…
I hav done research online, most code samples are string replace, not such variable replace. Anybody hav good idea? sample as follow:

before change:

<Param><Num>123</Num></Param>
<Param><Num>123</Num></Param>
<Param><Num>123</Num></Param>

after change:

<Param><Num>1000</Num></Param>
<Param><Num>1100</Num></Param>
<Param><Num>1200</Num></Param>

  • 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-11T00:11:37+00:00Added an answer on June 11, 2026 at 12:11 am

    Quite easy to achieve with the lxml library

    from lxml import  objectify
    
    class Parser(object):
        def __init__(self, tree, counter_start, counter_interval):
            self.tree = tree
            self.root = tree.getroot()
            self.counter_start = counter_start
            self.counter_interval = counter_interval
    
        def parse(self):
            counter = self.counter_start
            # for loop to iter voltage items
            # using counter += counter_interval to set the value for example
            # save the tree within the parser class or in the handle function
    
    
    def handle(file):
        f = open(file)
        tree = objectify.parse(f)
        parser = Parser(tree, 1000, 100)
        parser.parse()
        f.close()
    
    handle("/Desktop/bar.XML")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm filling an XML document manually using C# and I need to have <data>
I have a single xml document (data.xml), which I display as HTML using an
I need to write XML data to an encrypted file. I can read/write encrypted
I have a xml document as string. I need to insert the data into
I have an XML Document that specifies certain data instead data nodes like so:
I have a XML document with my data in it, multiple entries for the
I have a XML Document (LessonData.xml) with lesson data in it, with the following
I have a huge XML document 200MB in size containing textual information. The data
I have an XML document, and I want to print the tag names and
I have a heavily nested XML document that I need to load into my

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.