In the example below, how would you write the in-memory xmldoc to a text file? In my real situation, I send a string to a web service (code 2 below) which returns XML/KML that I want to save to a local file.
from: [HTML]http://www.faqs.org/docs/diveintopython/kgp_parse.html[/HTML]
2
Thanks!
from: [HTML]http://www.faqs.org/docs/diveintopython/kgp_parse.html[/HTML]
Code:
>>> from xml.dom import minidom >>> xmldoc = minidom.parse('~/diveintopython/common/py/kgp/binary.xml') >>> xmldoc <xml.dom.minidom.Document instance at 010BE87C> >>> print xmldoc.toxml() <?xml version="1.0" ?> <grammar> <ref id="bit"> <p>0</p> <p>1</p> </ref> <ref id="byte"> <p><xref id="bit"/><xref id="bit"/><xref id="bit"/><xref id="bit"/>\ <xref id="bit"/><xref id="bit"/><xref id="bit"/><xref id="bit"/></p> </ref> </grammar>
2
Code:
# from http://svn.python.org/projects/python/branches/release25-maint/Doc/howto/urllib2.rst import urllib, urllib2, arcgisscripting from xml.dom import minidom user_address = '8615 Westwood Center Drive, Vienna, VA, 22182' url = 'http://xxx.yyy.zzz' #geocoding servlet url - the one I use is internal values = {'address': user_address} data = urllib.urlencode(values) req = urllib2.Request(url, data) response = urllib2.urlopen(req) xmlResults = response.read() xmldoc = minidom.parseString(xmlResults) ##places = xmldoc.getElementsByTagName('Placemark') ## ##nameTag = places[0].getElementsByTagName('name') ##print nameTag[0].firstChild.wholeText ## ##descriptionTag = places[0].getElementsByTagName('description') ##print descriptionTag[0].firstChild.wholeText ## ##coordinatesTag = places[0].getElementsByTagName('coordinates') ##print coordinatesTag[0].firstChild.wholeText ## ##gp.SetParameterAsText(1,xmlResults) print xmldoc.toxml()
Comment