@@ -40,21 +40,32 @@ def getTreeBuilder(treeType, implementation=None, **kwargs):
4040
4141 "simpletree" - a built-in DOM-ish tree type with support for some
4242 more pythonic idioms.
43- "dom" - The xml.dom.minidom DOM implementation
43+ "dom" - A generic builder for DOM implementations, defaulting to
44+ a xml.dom.minidom based implementation for the sake of
45+ backwards compatibility (as releases up until 0.10 had a
46+ builder called "dom" that was a minidom implemenation).
4447 "etree" - A generic builder for tree implementations exposing an
4548 elementtree-like interface (known to work with
4649 ElementTree, cElementTree and lxml.etree).
4750 "beautifulsoup" - Beautiful soup (if installed)
4851
49- implementation - (Currently applies to the "etree"tree type only ). A module
50- implementing the tree type e.g. xml.etree.ElementTree or
51- lxml.etree."""
52+ implementation - (Currently applies to the "etree"and "dom" tree types ). A
53+ module implementing the tree type e.g.
54+ xml.etree.ElementTree or lxml.etree."""
5255
5356treeType = treeType .lower ()
5457if treeType not in treeBuilderCache :
55- if treeType in ("dom" ,"simpletree" ):
56- mod = __import__ (treeType ,globals ())
57- treeBuilderCache [treeType ]= mod .TreeBuilder
58+ if treeType == "dom" :
59+ import dom
60+ # XXX: Keep backwards compatibility by using minidom if no implementation is given
61+ if implementation == None :
62+ from xml .dom import minidom
63+ implementation = minidom
64+ # XXX: NEVER cache here, caching is done in the dom submodule
65+ return dom .getDomModule (implementation ,** kwargs ).TreeBuilder
66+ elif treeType == "simpletree" :
67+ import simpletree
68+ treeBuilderCache [treeType ]= simpletree .TreeBuilder
5869elif treeType == "beautifulsoup" :
5970import soup
6071treeBuilderCache [treeType ]= soup .TreeBuilder