14 Sep 2008 12:40
PyXML and DOM example 'generate_xml1.py'
David Lucena <yakumoklesk <at> yahoo.es>
2008-09-14 10:40:13 GMT
2008-09-14 10:40:13 GMT
I've started to use PyXML because I needed a xml library for a tool I am making. Due to lack of documentation, I
have been looking for the examples, but I've found some of them does not work. In fact, the fist I tested was
the one on the Subject. I have made some modifications get it to work. Here I paste the full file contents:
"""
A basic example of using the DOM to create an XML document from scratch.
"""
from xml.dom import ext
from xml.dom import implementation
if __name__ == '__main__':
#Create a doctype using document type name, sysid and pubid
dt = implementation.createDocumentType('mydoc', '', '')
#Create a document using document element namespace URI, doc element
#name and doctype. This automatically creates a document element
#which is the single element child of the document
doc = implementation.
( None, 'mydoc', dt)
#Get the document element
doc_elem = doc.documentElement
#Create an element: the Document instanmce acts as a factory
new_elem = doc.createElementNS( None, 'spam')
#Create an attribute on the new element
(Continue reading)
> I previously had problems with other programs I tried to install, as
> if no gcc compiler could be found, but do not know how to check that
> indeed
~ % cat > test.c
main () {}
~ % gcc test.c
~ % ./a.out
_______________________________________________
XML-SIG maillist - XML-SIG <at> python.org
RSS Feed