Generating XML.
Peter Hansen
peter at engcorp.com
Mon Mar 3 21:50:24 EST 2003
TuxedoKamen wrote:
>
> Hello. I have a program that needs to do the following:
> 1. Reads an XML file using the minidom interface
> 2. Proceeds to present the information to the user for viewing
> 3. Allows the user to update the information if desired
> 4. If user made any changes, saves updated information to XML file.
>
> I'm familiar with how to do one, two, and three, but four has me a
> little confused. I am assuming it is possible to manipulate the various
> nodes of the dom tree as necessary (this would certainly make editing the
> XML easy), but I don't see any mention of exporting the tree to an external
> textfile. Is this possible? If not, what's the best way to get a DOM tree
> out of an application and into a text file?
>>> from xml.dom.minidom import parseString
>>> d = parseString('<?xml version="1.0"?><root></root>')
>>> d.firstChild.appendChild(d.createTextNode('added text'))
<DOM Text node "added text">
>>> print d.toxml()
<?xml version="1.0" ?>
<root>added text</root>
Is that a help?
-Peter
More information about the Python-list
mailing list