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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:04:24+00:00 2026-06-12T23:04:24+00:00

I have an xml file as below and I want to read data from

  • 0

I have an xml file as below and I want to read data from my device and write the data into “value” column by using python script.

<TopoDefs>
  <Device Name="SNB" LogicalType="CORE" 
          IdCode="0x03886A21" Mask="0xf0000000">
    <Variable name="A0" value="0x52001321" type="GREEN" /> 
    <Variable name="A1" value="0x51001321" type="GREEN" /> 
    <Variable name="A2" value="0x03001321" type="GREEN" /> 
    <Variable name="A3" value="0x14001321" type="GREEN" /> 
    <Variable name="B0" value="0x5A001321" type="BLUE" /> 
    <Variable name="B1" value="0x51001321" type="BLUE" /> 
    <Variable name="B2" value="0x04001321" type="BLUE" /> 
    <Variable name="B3" value="0x05001321" type="BLUE" />
  </Device>
</TopoDefs>

I am completely a new learner of python scripting. How to parse the xml file and point to the attribute value to replaced by a new value that will changed all the time?
If i using getElementsByTagName and nodevalue, it would read all the string of the node, how do I limit by reading the value only and the other variables remain the same?

  • 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-12T23:04:25+00:00Added an answer on June 12, 2026 at 11:04 pm

    Here’s an example that iterates over all the Devices in the document, and all the Variables in a Device:

    xmlstr = """<TopoDefs>
      <Device Name="SNB" LogicalType="CORE"
              IdCode="0x03886A21" Mask="0xf0000000">
        <Variable name="A0" value="0x52001321" type="GREEN" />
        <Variable name="A1" value="0x51001321" type="GREEN" />
        <Variable name="A2" value="0x03001321" type="GREEN" />
        <Variable name="A3" value="0x14001321" type="GREEN" />
        <Variable name="B0" value="0x5A001321" type="BLUE" />
        <Variable name="B1" value="0x51001321" type="BLUE" />
        <Variable name="B2" value="0x04001321" type="BLUE" />
        <Variable name="B3" value="0x05001321" type="BLUE" />
      </Device>
    </TopoDefs>"""
    
    import xml.etree.ElementTree as ET
    document = ET.fromstring(xmlstr)
    
    for dev in document.iter('Device'):
        for var in dev.iter('Variable'):
            var.set('value', 'new_value')
    
    print ET.tostring(document)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml file as below and I want to read data from
I have the below XML file <?xml version=1.0 encoding=iso-8859-1?> <DATASET> <TYPE>success</TYPE> <RECORD> <DATA type=email>eeee@eee.net</DATA>
need help to read xml file. i have one xml file which i want
i want to read an xml file in flash that is returned from a
I have an XML file that I want to transform using an XSLT. It
I have an xml file in which i want to read the child nodes
I am reading xml gps data using xmlreader.read(). I want to output all coordinate
i have xml file like below.I want to find specific text values in different
I have an xml file likes below. <?xml version=1.0 encoding=utf-8 ?> <Book> <Title>Title</Title> <Content>Content</Content>
I have a xml file as below: <?xml version=1.0 encoding=UTF-8 standalone=no?> <RULES> <RULE DESCRIPTION=

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.