# HG changeset patch # User paulb # Date 1134322060 0 # Node ID f930adb82cef2f810c12ba837deab959a94479ef # Parent c5c812567b4f64a911f98494737c847411b557ca [project @ 2005-12-11 17:27:40 by paulb] Added namespaceURI tests. diff -r c5c812567b4f -r f930adb82cef tests/namespaces.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/namespaces.py Sun Dec 11 17:27:40 2005 +0000 @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +import libxml2dom, xml.dom.minidom + +document = libxml2dom.createDocument(None, "doc", None) +top = document.xpath("*")[0] +elem1 = document.createElementNS("DAV:", "href") +document.replaceChild(elem1, top) +elem2 = document.createElementNS(None, "no_ns") +document.xpath("*")[0].appendChild(elem2) +print document.toString() +document.toFile(open("test_ns.xml", "wb")) + +document = libxml2dom.parse("test_ns.xml") +print "Namespace is", repr(document.xpath("*")[0].namespaceURI) + +document = xml.dom.minidom.Document() +elem1 = document.createElementNS("DAV:", "href") +document.appendChild(elem1) +elem2 = document.createElementNS(None, "no_ns") +document.childNodes[0].appendChild(elem2) +print document.toxml() +open("test_ns.xml", "wb").write(document.toxml()) + +document = xml.dom.minidom.parse("test_ns.xml") +print "Namespace is", repr(document.documentElement.namespaceURI) + +try: + from xml.dom.ext import PrettyPrint + PrettyPrint(document) + PrettyPrint(document, stream=open("test_ns.xml", "wb")) + + document = xml.dom.minidom.parse("test_ns.xml") + print "Namespace is", repr(document.documentElement.namespaceURI) + +except ImportError: + print "Prettyprinted document not produced." + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r c5c812567b4f -r f930adb82cef tests/namespaces2.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/namespaces2.py Sun Dec 11 17:27:40 2005 +0000 @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +import libxml2dom, xml.dom, xml.dom.minidom + +document = libxml2dom.createDocument(None, "doc", None) +top = document.xpath("*")[0] +elem1 = document.createElementNS("DAV:", "myns:href") +elem1.setAttributeNS(xml.dom.XMLNS_NAMESPACE, "xmlns:myns", "DAV:") +document.replaceChild(elem1, top) +print document.toString() + +document = xml.dom.minidom.Document() +elem1 = document.createElementNS("DAV:", "myns:href") +elem1.setAttributeNS(xml.dom.XMLNS_NAMESPACE, "xmlns:myns", "DAV:") +document.appendChild(elem1) +print document.toxml() + +# vim: tabstop=4 expandtab shiftwidth=4