Python: Get value with xmltodict

前端 未结 1 1116
长发绾君心
长发绾君心 2021-01-29 02:20

I have an XML-file that looks like this:



    &l         


        
1条回答
  •  闹比i
    闹比i (楼主)
    2021-01-29 02:46

    What you are getting is a list of fields where every field is represented by a dict(). Explore this dict (e.g. in Python interactive shell) to narrow down how to get to the value you want.

    >>> doc["session"]["docInfo"]["field"][0]
    OrderedDict([(u'@name', u'Employee'), (u'@isMandotory', u'True'), ('#text', u'Jake Roberts')])
    

    In order to get to the element value add ["#text"] to the end of the line in the snippet above.

    0 讨论(0)
提交回复
热议问题