5 from Ft
.Xml
.Domlette
import Node
, implementation
6 from Ft
.Xml
import XMLNS_NAMESPACE
7 from Ft
.Xml
.Lib
.Nss
import GetAllNs
9 from string
import find
, lower
, join
10 from socket
import gethostbyaddr
, gethostname
12 def node_to_xml(node
):
13 "Takes an XML node and returns an XML documentElement suitable for saving."
14 root
= implementation
.createDocument(None, 'root', None)
15 new
= node
.cloneNode(deep
= 1)
16 new
= root
.importNode(new
, deep
= 1)
17 root
.replaceChild(new
, root
.documentElement
)
20 def node_to_html(node
):
21 "Takes an XML node and returns an HTML documentElement suitable for saving."
22 root
= implementation
.createHTMLDocument('HTML document')
23 def html(doc
, node
, html
):
24 new
= doc
.importNode(node
.cloneNode(deep
= 0), deep
= 0)
25 if node
.nodeType
== Node
.ELEMENT_NODE
:
26 for a
in node
.attributes
:
27 new
.setAttribute(a
.localName
, a
.value
)
28 for k
in node
.childNodes
:
29 new
.appendChild(html(doc
, k
, html
))
31 new
= html(root
, node
, html
)
32 root
.replaceChild(new
, root
.documentElement
)
35 def send_to_file(data
, path
):
37 file = open(path
, 'wb')
43 rox
.report_exception()
48 def import_with_ns(doc
, node
):
51 node
= doc
.importNode(node
, 1)
61 node
.setAttributeNS(XMLNS_NAMESPACE
, ns
, uri
)