I’m writing a python class to parse XML and pull out tag names and their values. So far I have just been passing XML files to my class and parsing it using ElementTree.
Inevitably I’d like to be able to pass a variety of XML formats to the class, so not only files but possibly XML strings or XML from URL’s.
I’m not sure what would be the best way to go about this. I was thinking of writing a seperate class or def to convert all XML information to a single format e.g string. Then have my parsing class set up just to accept XML strings for parsing.
If anyone has a suggestion on how to best solve this question that would be great and how to do it would be even better :).
Thanks.
Use LXML. It can parse XML from strings, files or URLs, out of the box.