Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

xml to json in python

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

def dumpAddressing():
    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

    js = json.dumps(dict)
    f = open("json/addressing.json", "w")
    f.write(js)
    f.close()
Comment

PREVIOUS NEXT
Code Example
Python :: iterate over dataframe 
Python :: python compare floats 
Python :: remove item list python 
Python :: pandas excel sheet name 
Python :: uploading folder in google colab 
Python :: linear search python 
Python :: python alphabetical order 
Python :: discord.py embed 
Python :: pandas get group 
Python :: django reverse function 
Python :: python fractions 
Python :: fibonacci series using recursion in python 
Python :: python program to check if binary representation is a palindrome 
Python :: multiple lines input python 
Python :: python extract list from string 
Python :: python compare sets 
Python :: queue using linked list in python 
Python :: pandas drop duplicate keep last 
Python :: python remove many items via index at oncefrom a list? 
Python :: Read JSON files with automatic schema inference 
Python :: quick sort python 
Python :: concardinate str and a variable in python 
Python :: python delete from dictionary 
Python :: how to replace a word in text file using python 
Python :: insert row in any position pandas dataframe 
Python :: all frequency offset in pandas 
Python :: extract text from pdf python 
Python :: driver code in python 
Python :: pandas apply output multiple columns 
Python :: create dict from two lists 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =