Lines Matching refs:dom
1 # test for xml.dom.minidom
10 import xml.dom.minidom
12 from xml.dom.minidom import parse, Attr, Node, Document, parseString
13 from xml.dom.minidom import getDOMImplementation
36 notation = xml.dom.minidom.Notation("my-notation", None,
39 entity = xml.dom.minidom.Entity("my-entity", None,
70 dom = parse(file)
71 dom.unlink()
72 self.confirm(isinstance(dom, Document))
76 dom = parse(file)
77 dom.unlink()
78 self.confirm(isinstance(dom, Document))
95 dom = parse(tstfile)
96 self.confirm(dom.getElementsByTagName("LI") == \
97 dom.documentElement.getElementsByTagName("LI"))
98 dom.unlink()
101 dom = parseString("<doc><foo/></doc>")
102 root = dom.documentElement
104 nelem = dom.createElement("element")
116 nelem = dom.createElement("element")
128 nelem2 = dom.createElement("bar")
141 dom.unlink()
144 dom = parseString("<doc/>")
145 orig = dom.createTextNode("original")
146 c1 = dom.createTextNode("foo")
147 c2 = dom.createTextNode("bar")
148 c3 = dom.createTextNode("bat")
149 dom.documentElement.appendChild(orig)
150 frag = dom.createDocumentFragment()
154 return dom, orig, c1, c2, c3, frag
157 dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
158 dom.documentElement.insertBefore(frag, None)
159 self.confirm(tuple(dom.documentElement.childNodes) ==
163 dom.unlink()
165 dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
166 dom.documentElement.insertBefore(frag, orig)
167 self.confirm(tuple(dom.documentElement.childNodes) ==
171 dom.unlink()
174 dom = parse(tstfile)
175 dom.documentElement.appendChild(dom.createComment("Hello"))
176 self.confirm(dom.documentElement.childNodes[-1].nodeName == "#comment")
177 self.confirm(dom.documentElement.childNodes[-1].data == "Hello")
178 dom.unlink()
181 dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
182 dom.documentElement.appendChild(frag)
183 self.confirm(tuple(dom.documentElement.childNodes) ==
187 dom.unlink()
190 dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
191 dom.documentElement.replaceChild(frag, orig)
193 self.confirm(tuple(dom.documentElement.childNodes) == (c1, c2, c3),
196 dom.unlink()
199 dom = Document()
200 elem = dom.createElement('element')
201 text = dom.createTextNode('text')
202 self.assertRaises(xml.dom.HierarchyRequestErr, dom.appendChild, text)
204 dom.appendChild(elem)
205 self.assertRaises(xml.dom.HierarchyRequestErr, dom.insertBefore, text,
207 self.assertRaises(xml.dom.HierarchyRequestErr, dom.replaceChild, text,
211 self.assertRaises(xml.dom.HierarchyRequestErr, nodemap.setNamedItem,
213 self.assertRaises(xml.dom.HierarchyRequestErr, nodemap.setNamedItemNS,
217 dom.unlink()
220 dom = Document()
221 elem = dom.createElement('element')
225 self.confirm(a.ownerDocument is dom,
234 dom.unlink()
237 dom = parse(tstfile)
238 self.confirm(dom)# should not be zero
239 dom.appendChild(dom.createComment("foo"))
240 self.confirm(not dom.childNodes[-1].childNodes)
241 dom.unlink()
244 dom = parse(tstfile)
245 self.assertTrue(dom.childNodes)
246 dom.unlink()
247 self.assertFalse(dom.childNodes)
250 with parse(tstfile) as dom:
251 self.assertTrue(dom.childNodes)
252 self.assertFalse(dom.childNodes)
255 dom = Document()
256 dom.appendChild(dom.createElement("abc"))
257 self.confirm(dom.documentElement)
258 dom.unlink()
261 dom = parseString("<abc/>")
262 el = dom.documentElement
266 self.confirm(a.ownerDocument is dom,
268 self.confirm(a.ownerElement is dom.documentElement,
270 dom.unlink()
273 dom = parseString("<abc/>")
274 el = dom.documentElement
278 dom.unlink()
281 dom = Document()
282 child = dom.appendChild(dom.createElement("abc"))
299 dom.unlink()
302 dom = Document()
303 child = dom.appendChild(dom.createElement("abc"))
310 dom.unlink()
313 dom = Document()
314 child = dom.appendChild(dom.createElement("abc"))
318 self.assertRaises(xml.dom.NotFoundErr, child.removeAttribute, "foo")
321 dom.unlink()
324 dom = Document()
325 child = dom.appendChild(
326 dom.createElementNS("http://www.python.org", "python:abc"))
330 self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNS,
335 dom.unlink()
338 dom = Document()
339 child = dom.appendChild(dom.createElement("foo"))
343 self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode,
351 self.assertRaises(xml.dom.NotFoundErr, child2.removeAttributeNode,
353 dom.unlink()
356 dom = Document()
357 child = dom.appendChild(dom.createElement("foo"))
362 dom = parseString("<abc/>")
363 el = dom.documentElement
397 dom.unlink()
409 dom = Document()
410 child = dom.appendChild(
411 dom.createElementNS("http://www.python.org", "python:abc"))
415 dom = Document()
416 child = dom.appendChild(
417 dom.createElementNS("http://www.python.org", "python:abc"))
424 child2 = child.appendChild(dom.createElement('abc'))
434 dom = parseString(d)
435 elems = dom.getElementsByTagNameNS("http://pyxml.sf.net/minidom",
443 dom.unlink()
468 dom = Document()
469 el = dom.appendChild(dom.createElement("abc"))
473 dom.unlink()
476 dom = Document()
477 el = dom.appendChild(dom.createElement("abc"))
481 dom.unlink()
484 dom = Document()
485 el = dom.appendChild(
486 dom.createElementNS("http://www.slashdot.org", "slash:abc"))
491 dom.unlink()
494 dom = Document()
495 el = dom.appendChild(dom.createElement("abc"))
498 dom.unlink()
504 dom = parseString(str)
505 domstr = dom.toxml()
506 dom.unlink()
511 dom = parseString(str)
512 domstr = dom.toprettyxml(newl="\r\n")
513 dom.unlink()
532 dom = Document()
533 elem = dom.createElement('elem')
534 elem.appendChild(dom.createTextNode('TEXT'))
535 elem.appendChild(dom.createTextNode('TEXT'))
536 dom.appendChild(elem)
538 self.assertEqual(dom.toprettyxml(),
544 dom = parseString(str)
545 dom2 = parseString(dom.toprettyxml())
547 dom.getElementsByTagName('B')[0].childNodes[0].toxml(),
551 dom = parseString('<e><?mypi \t\n data \t\n ?></e>')
552 pi = dom.documentElement.firstChild
563 and pi.namespaceURI == xml.dom.EMPTY_NAMESPACE)
577 self.assertRaises(xml.dom.HierarchyRequestErr, doc.appendChild, elem)
608 self.assertRaises(xml.dom.NotFoundErr, attrs.removeNamedItem, "a")
617 self.assertRaises(xml.dom.NotFoundErr, attrs.removeNamedItemNS,
645 dom = parseString("<doc><foo/></doc>")
646 doc = dom.documentElement
673 dom = parseString("<doc attr='value'><foo/></doc>")
674 root = dom.documentElement
682 return dom, clone
685 dom, clone = self._setupCloneElement(0)
691 dom.unlink()
694 dom, clone = self._setupCloneElement(1)
700 dom.unlink()
800 self.assertRaises(xml.dom.NotSupportedErr, doc1.importNode, doc2, deep)
811 self.assertRaises(xml.dom.NotSupportedErr, target.importNode,
817 self.assertRaises(xml.dom.NotSupportedErr, target.importNode,
859 document = xml.dom.minidom.parseString("""
887 operation = xml.dom.UserDataHandler.NODE_IMPORTED
894 operation = xml.dom.UserDataHandler.NODE_CLONED
1201 dom = Document()
1202 n = dom.createElement('e')
1222 dom.unlink()
1226 self.assertRaises(xml.dom.NamespaceErr, doc.renameNode, node,
1229 self.assertRaises(xml.dom.WrongDocumentErr, doc2.renameNode, node,
1230 xml.dom.EMPTY_NAMESPACE, "foo")
1239 attr = doc.renameNode(attr, xml.dom.EMPTY_NAMESPACE, "b")
1243 and attr.namespaceURI == xml.dom.EMPTY_NAMESPACE
1288 attr = doc.renameNode(attr, xml.dom.EMPTY_NAMESPACE, "e")
1292 and attr.namespaceURI == xml.dom.EMPTY_NAMESPACE
1304 self.assertRaises(xml.dom.NamespaceErr, doc.renameNode, attr,
1314 elem = doc.renameNode(elem, xml.dom.EMPTY_NAMESPACE, "a")
1318 and elem.namespaceURI == xml.dom.EMPTY_NAMESPACE
1341 elem = doc.renameNode(elem, xml.dom.EMPTY_NAMESPACE, "d")
1345 and elem.namespaceURI == xml.dom.EMPTY_NAMESPACE
1355 doc = xml.dom.minidom.getDOMImplementation().createDocument(
1356 xml.dom.EMPTY_NAMESPACE, "e", None)
1358 self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
1359 xml.dom.EMPTY_NAMESPACE, "foo")
1461 and t.namespace == xml.dom.EMPTY_NAMESPACE)
1467 and t.namespace == xml.dom.EMPTY_NAMESPACE)
1496 doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an")
1532 doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an")
1568 doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an")
1631 self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
1645 self.assertRaises( xml.dom.NotFoundErr, doc.removeChild, title_tag)