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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:18:51+00:00 2026-06-13T00:18:51+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 on certain name 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>

May I asks how to I point to the variable A0 to write a new data on “value” attribute?
What is the differences among find, findall, iterfind, itertext?

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

    Using lxml , that I argue is the best tool available for the task:

    from lxml import etree as ET
    
    
    >>> root = ET.fromstring('<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>')
    >>> root.xpath('.//Variable[@name="A0"]')[0].attrib['value']='test'
    >>> print ET.tostring(root,pretty_print=True)
    <TopoDefs>
      <Device Name="SNB" LogicalType="CORE" IdCode="0x03886A21" Mask="0xf0000000">
        <Variable name="A0" value="test" 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>
    

    Or you can loop through Variables and change all values as I understood you wanted:

    >>> for i in root.xpath('.//Variable'):
    ...     i.attrib['value']='CHANGE'
    ...     
    >>> print ET.tostring(root,pretty_print=True)
    <TopoDefs>
      <Device Name="SNB" LogicalType="CORE" IdCode="0x03886A21" Mask="0xf0000000">
        <Variable name="A0" value="CHANGE" type="GREEN"/>
        <Variable name="A1" value="CHANGE" type="GREEN"/>
        <Variable name="A2" value="CHANGE" type="GREEN"/>
        <Variable name="A3" value="CHANGE" type="GREEN"/>
        <Variable name="B0" value="CHANGE" type="BLUE"/>
        <Variable name="B1" value="CHANGE" type="BLUE"/>
        <Variable name="B2" value="CHANGE" type="BLUE"/>
        <Variable name="B3" value="CHANGE" type="BLUE"/>
      </Device>
    </TopoDefs>
    
    • 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 in which i want to read the child nodes
I have xml file as below: <Name ns1:translate=yes>Overview</Name> <TextValue>Start</TextValue> <Title ns1:translate=yes>This is a book</Title>
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=
I have a long xml file the content of the file are below: <?xml

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.