python - How to retrieve the xml which has been created using the minidom? -


 xml.dom.minidom import document   def generatexml():      # create minidom document     doc = document()      # create <discover> base element     discover = doc.createelement("discover")     doc.appendchild(discover)       # create main <host> element     host = doc.createelement("host")     host.appendchild(discover)      # create main <ip> element     ip = doc.createelement("ip")     ip.appendchild(host)      # assign <ip> element ip address     ipaddrr = doc.createtextnode('10.193.184.72')     ip.appendchild(ipaddrr)      # create main <hostname> element     hostname = doc.createelement("hostname")     hostname.appendchild(host)      # assign <hostname> element hostname     hostname_value = doc.createtextnode('darknight')     hostname.appendchild(hostname_value)      # create main <ostype> element     ostype = doc.createelement("ostype")     ostype.appendchild(host)      # assign <ostype> element ostype     ostype_value = doc.createtextnode('mac')     ostype.appendchild(ostype_value)      return doc.toprettyxml()   print generatexml() 

now when print it -- returning <?xml version="1.0" ?> , want whole xml created. please help

you appending elements wrong way. it's parentnode.appendchild(childnode), you've written childnode.appendchild(parentnode)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -