+ 18
Is there a 100% effective method to convert or import a complex XML file into Python?
I tried with several tools that I found on Internet. But, all of them are only suitable for simple XML files. ElementTree, DOM, SAX, Soap were some of them! Using the search bar did not give me a satisfactory result either. A book of Python for Data Science gave me some insights, but I am unsure if it's viable or not. Maybe, there is a possibility with LXML but using a C++ library and with more advanced XPath expressions. If you have a solution or easier way to accomplish it, I would really appreciate your help. Thanks!
5 ответов
+ 19
Have you tried beautifulsoup? It is really cool for parsing HTML, but also XML. It is very flexible and logical, thus should have no problem with dealing with files of any given complexity.
+ 9
Kuba Siekierzynński I haven't reviewed in detail that one but it also seems to be a good option together with lxml or html5lib parsers. I'm gonna try!
+ 6
I've used lxml for python for age. It has support for both HTML and XML. It supports different parsers for different charsets/encodings. Importing from an url, a file or a string containing the content of the xml should be no problem.
+ 3
BeautifulSoup does a good job at this.
Lxml is good too
- 2
diese Frage gehört nicht hierhin. Stellt doch die Fragen, wo es Sinn macht, statt da alles zu verstopfen, wo ich Antworten zu konkreten Fragen suche