Working with HTML5 documents

Denis McMahon denismfmcmahon at gmail.com
Wed Nov 19 16:08:03 EST 2014


So what I'm looking for is a method to create an html5 document using "dom 
manipulation", ie:

doc = new htmldocument(doctype="HTML")
html = new html5element("html")
doc.appendChild(html)
head = new html5element("body")
html.appendChild(head)
body = new html5element("body")
html.appendChild(body)
title = new html5element("title")
txt = new textnode("This Is The Title")
title.appendChild(txt)
head.appendChild(title)
para = new html5element("p")
txt = new textnode("This is some text.")
para.appendChild(txt)
body.appendChild(para)

print(doc.serialise())

generates:

<!doctype HTML><html><head><title>This Is The Title</title></
head><body><p>This is some text.</p></body></html>

I'm finding various mechanisms to generate the structure from an existing 
piece of html (eg html5lib, beautifulsoup etc) but I can't seem to find 
any mechanism to generate, manipulate and produce html5 documents using 
this dom manipulation approach. Where should I be looking?

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list