Thursday, March 8, 2018

python parse xml text




I would like to parse xml in python, but as a string, not taken from a file. Can someone help me do this?


Answer



From a file, you could normally do it as




from xml.dom import minidom                                          
xmldoc = minidom.parse('~/diveintopython/common/py/kgp/binary.xml')


For a string, you can change it to



from xml.dom import minidom                                          
xmldoc = minidom.parseString( Your string goes here )


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...