1.1 --- a/libxml2dom/macrolib/__init__.py Thu Dec 15 18:24:32 2005 +0000
1.2 +++ b/libxml2dom/macrolib/__init__.py Thu Dec 15 18:25:43 2005 +0000
1.3 @@ -20,7 +20,7 @@
1.4 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
1.5 """
1.6
1.7 -__version__ = "0.3.3"
1.8 +__version__ = "0.3.4"
1.9
1.10 # Expose all functions here.
1.11
2.1 --- a/libxml2dom/macrolib/macrolib.py Thu Dec 15 18:24:32 2005 +0000
2.2 +++ b/libxml2dom/macrolib/macrolib.py Thu Dec 15 18:25:43 2005 +0000
2.3 @@ -78,7 +78,7 @@
2.4 def _check_namespace(current, ns, prefix):
2.5 current_ns = libxml2mod.xmlNodeGetContent(current)
2.6 current_prefix = libxml2mod.name(current)
2.7 - if ns == current_ns and prefix == current_prefix:
2.8 + if ns == current_ns and (prefix is None or prefix == current_prefix):
2.9 return 1
2.10 else:
2.11 return 0
2.12 @@ -90,6 +90,20 @@
2.13 new_ns = None
2.14 return new_ns
2.15
2.16 +def _get_invented_prefix(node, ns):
2.17 + current = libxml2mod.xmlNodeGetNsDefs(node)
2.18 + prefixes = []
2.19 + while current is not None:
2.20 + current_prefix = libxml2mod.name(current)
2.21 + prefixes.append(current_prefix)
2.22 + current = libxml2mod.next(current)
2.23 + i = 0
2.24 + while 1:
2.25 + prefix = "NS%d" % i
2.26 + if prefix not in prefixes:
2.27 + return prefix
2.28 + i += 1
2.29 +
2.30 _nodeTypes = {
2.31 "attribute" : xml.dom.Node.ATTRIBUTE_NODE,
2.32 "comment" : xml.dom.Node.COMMENT_NODE,
2.33 @@ -238,8 +252,13 @@
2.34 # For non-xmlns attributes, we find or make a namespace declaration and then
2.35 # set an attribute.
2.36 elif ns is not None:
2.37 + # Look for a suitable namespace.
2.38 new_ns = _find_namespace(node, ns, prefix)
2.39 + # Create a declaration if no suitable one was found.
2.40 if new_ns is None:
2.41 + # Invent a prefix for unprefixed attributes with namespaces.
2.42 + if prefix is None:
2.43 + prefix = _get_invented_prefix(node, ns)
2.44 new_ns = _make_namespace(node, ns, prefix, set_default=0)
2.45 libxml2mod.xmlSetNsProp(node, new_ns, localName, value)
2.46 else: