Get Element value with minidom with Python

前端 未结 9 2001
悲&欢浪女
悲&欢浪女 2020-11-29 18:01

I am creating a GUI frontend for the Eve Online API in Python.

I have successfully pulled the XML data from their server.

I am trying to grab the value from

9条回答
  •  失恋的感觉
    2020-11-29 18:25

    Probably something like this if it's the text part you want...

    from xml.dom.minidom import parse
    dom = parse("C:\\eve.xml")
    name = dom.getElementsByTagName('name')
    
    print " ".join(t.nodeValue for t in name[0].childNodes if t.nodeType == t.TEXT_NODE)
    

    The text part of a node is considered a node in itself placed as a child-node of the one you asked for. Thus you will want to go through all its children and find all child nodes that are text nodes. A node can have several text nodes; eg.

    
      blabla
      asdf
      znylpx
    
    

    You want both 'blabla' and 'znylpx'; hence the " ".join(). You might want to replace the space with a newline or so, or perhaps by nothing.

提交回复
热议问题