Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python read xml

from xml.dom import minidom

# parse an xml file by name
mydoc = minidom.parse('items.xml')

items = mydoc.getElementsByTagName('item')

# one specific item attribute
print('Item #2 attribute:')
print(items[1].attributes['name'].value)

# all item attributes
print('
All attributes:')
for elem in items:
    print(elem.attributes['name'].value)

# one specific item's data
print('
Item #2 data:')
print(items[1].firstChild.data)
print(items[1].childNodes[0].data)

# all items data
print('
All item data:')
for elem in items:
    print(elem.firstChild.data)
Comment

read xml file in python

import  xml.dom.minidom
from xml.dom import getChildNodesByName


xdom = xml.dom.minidom.parse("GenericAddressing.xml")
xdoc = xdom.documentElement
dict = {}
xml_funcs = getChildNodesByName(xdoc, u"Function")
for func in xml_funcs:
    shortname = func.getAttribute(u"Name")
    address = func.getAttribute(u"Address")
    for name in  getChildNodesByName(func, u"Name"):
        longname = name.firstChild.nodeValue
        dict[hex(int(address))[2:].upper()] = (shortname, longname)
        break
Comment

PREVIOUS NEXT
Code Example
Python :: is string python 
Python :: python format datetime 
Python :: which python mac 
Python :: python push into array if not exists 
Python :: how to get pygame window height size 
Python :: quadratic formula python 
Python :: ignore bad lines pandas 
Python :: factorial python for loop 
Python :: rvec tvec ros message 
Python :: Python Enemy NPC CLass 
Python :: django override help text 
Python :: Liczby zespolone Python 
Python :: prekladac 
Python :: python input with space 
Python :: upgrade python to 3.9 i linux 
Python :: how to view the whole dataset in jupyternotebook 
Python :: dashes seaborn 
Python :: dynamo scripts template 
Python :: how to ask python function to return something 
Python :: per gjera te shumta. Python 
Python :: pil to grayscale 
Python :: python selenium wait for page to load 
Python :: convert tibble to dataframe 
Python :: sdsdsdsdsddsdddsdsdsdsdsdsdsdsdsdsdsdsdsdssdsdsdsdsdsdsdssssssddsdssdssssdsdsdsdsdsdsdsdsdsdsdsdsdsdssdssdsdsdsdsdsdsdsdsdsdsdssd 
Python :: numpy multiply by inverse square root of value 
Python :: how to move file from one location to another with python 
Python :: how to find range of dates in between two dates unsing python 
Python :: python -m http 
Python :: how to give multiple option to the user and ask the same question again and again until the user tells one of the options 
Python :: Insert numpy array to column 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =