1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/namespaces.py Sun Dec 11 17:27:40 2005 +0000
1.3 @@ -0,0 +1,39 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +import libxml2dom, xml.dom.minidom
1.7 +
1.8 +document = libxml2dom.createDocument(None, "doc", None)
1.9 +top = document.xpath("*")[0]
1.10 +elem1 = document.createElementNS("DAV:", "href")
1.11 +document.replaceChild(elem1, top)
1.12 +elem2 = document.createElementNS(None, "no_ns")
1.13 +document.xpath("*")[0].appendChild(elem2)
1.14 +print document.toString()
1.15 +document.toFile(open("test_ns.xml", "wb"))
1.16 +
1.17 +document = libxml2dom.parse("test_ns.xml")
1.18 +print "Namespace is", repr(document.xpath("*")[0].namespaceURI)
1.19 +
1.20 +document = xml.dom.minidom.Document()
1.21 +elem1 = document.createElementNS("DAV:", "href")
1.22 +document.appendChild(elem1)
1.23 +elem2 = document.createElementNS(None, "no_ns")
1.24 +document.childNodes[0].appendChild(elem2)
1.25 +print document.toxml()
1.26 +open("test_ns.xml", "wb").write(document.toxml())
1.27 +
1.28 +document = xml.dom.minidom.parse("test_ns.xml")
1.29 +print "Namespace is", repr(document.documentElement.namespaceURI)
1.30 +
1.31 +try:
1.32 + from xml.dom.ext import PrettyPrint
1.33 + PrettyPrint(document)
1.34 + PrettyPrint(document, stream=open("test_ns.xml", "wb"))
1.35 +
1.36 + document = xml.dom.minidom.parse("test_ns.xml")
1.37 + print "Namespace is", repr(document.documentElement.namespaceURI)
1.38 +
1.39 +except ImportError:
1.40 + print "Prettyprinted document not produced."
1.41 +
1.42 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/namespaces2.py Sun Dec 11 17:27:40 2005 +0000
2.3 @@ -0,0 +1,18 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +import libxml2dom, xml.dom, xml.dom.minidom
2.7 +
2.8 +document = libxml2dom.createDocument(None, "doc", None)
2.9 +top = document.xpath("*")[0]
2.10 +elem1 = document.createElementNS("DAV:", "myns:href")
2.11 +elem1.setAttributeNS(xml.dom.XMLNS_NAMESPACE, "xmlns:myns", "DAV:")
2.12 +document.replaceChild(elem1, top)
2.13 +print document.toString()
2.14 +
2.15 +document = xml.dom.minidom.Document()
2.16 +elem1 = document.createElementNS("DAV:", "myns:href")
2.17 +elem1.setAttributeNS(xml.dom.XMLNS_NAMESPACE, "xmlns:myns", "DAV:")
2.18 +document.appendChild(elem1)
2.19 +print document.toxml()
2.20 +
2.21 +# vim: tabstop=4 expandtab shiftwidth=4