Answer the question
In order to leave comments, you need to log in
Can't parse xml with lxml python?
Good afternoon. I can not generate the required dictionary
, there is xml
<one val='value1'>
<text> text1 </text>
<two>
<text> text two 1</text>
</two>
<two>
<text> text two 2</text>
</two>
<two>
<text> text two 3</text>
</two>
</one>
<one val='value2'>
<text> text2 </text>
<two>
<text> text two 4</text>
</two>
<two>
<text> text two 5</text>
</two>
</one>
<one val='value3'>
<text> text3 </text>
<two>
<text> text two 6</text>
</two>
</one>
Answer the question
In order to leave comments, you need to log in
You don't need XPath. lxml.de/tutorial.html#elements-are-lists
Do iterate over elements and recursive function (or just nested loops).
What's bad is that your XML structure ambiguously matches the structure of python dictionaries. Well, the given XML is invalid - there is no root element (or is it incomplete?).
def to_dicts(element):
obj = {'tag': element.tag,
'attrs': element.attrs,
'childs': [to_dicts(child) for child in element]}
return obj
SeriyPS, are ready to offer you a job on the topic of Parsing. The project is large, interesting and long-term, socially oriented and with good karma. First by piecework, then by agreement. We are ready to invest 200K or more in the topic.
Can you share contacts for communication?
1. Check ping to this ip
2. connect first with the help of any client (graphical or from the command line through the standard mysql client)
If everything is ok. Then google how exactly with the help to connect to the database.
If not ok, then the database server is not running. Or incorrect connection data. No driver is needed on the server. Except for the server itself and permissions to connect to it from any IP.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question