attribute values. Just using escape() can (and always has) led to broken
XML being generated. This makes sure it always produces the right thing.
This actually closes SF bug #440351.
If pyexpat is not available and more than one attempt is made to load
an expat-based xml parser, an empty xml.parser.expat module will be
created. This empty module will confuse xml.sax.expatreader into
thinking that pyexpat is available.
The ugly fix is to verify that the expat module actually defines the
names that are imported from pyexpat.
createAttributeNS(), use the parallel setAttributeNode() or
setAttributeNodeNS() to add the node to the document -- do not assume
that setAttributeNode() will operate properly for both.
- addition of a DocumentFragment implementation and createDocumentFragment method
- proper setting of ownerDocument for all nodes
- setting of namespaceURI to None in Element as a class attribute
- addition of setAttributeNodeNS and removeAttributeNodeNS as aliases
for setAttributeNode and removeAttributeNode
- support for inheriting from DOMImplementation to extend it with
additional features (to override the Document class)
in pulldom:
- support for nodes (comment and PI) that occur before he document element;
that became necessary as pulldom now delays creation of the document
until it has the document element.
NamedNodeMap.setNamedItem(). Martin, should I sync the PyXML tree, too,
or do you want to do it? (I don't know if you're wrapping the 0.6.4
release right now.)
New method; this is the "alternate" access to the exception code.
(Useful for Python DOM implementations that support the accessor
method approach to retrieving attribute values.)
This will make it incompatible with the version found in Python 2.0.
Does this need to be done to PyXML too?
Changes that might break existing code are marked with (!) below.
- Formatting nit: no spaces inside parentheses: foo( a ) -> foo(a).
- Break long lines.
- (!) Fix getAttribute() and getAttributeNS() to return "" instead of
raising KeyError when the attribute is not found.
- (!) Fix getAttributeNodeNS() to return None instead of raising
KeyError. (Curiously, getAttributeNode() already did this.)
- Added hasAttributes(), which returns true iff the node has any
attributes. )This is DOM level 3.)
- (!) In createDocument(), if the qualified name is not empty,
actually create and insert the first element with that name (this
will become doc.documentElement). MvL believes that it should be an
error to specify an empty qualified name; I'm not going there today,
since it would require making a matching change to pulldom. Maybe
MvL will do this.
- In Document.writexml(), insert an xml declaration at the top. (This
doesn't include the encoding since there's no way to specify the
encoding. If that's preferred, all writexml() methods should be
fixed to support an optional encoding argument that they pass to
each other -- and they should use it to encode all text they write,
too. Later.)
- implement hasAttribute and hasAttributeNS (1.7)
- Node.replaceChild(): Update the sibling nodes to point to newChild. Set
the .nextSibling attribute on oldChild instead of adding a .newChild
attribute (1.9).
give minidom.py behaviour that complies with the DOM Level 1 REC,
which says that when a node newChild is added to the tree, "if the
newChild is already in the tree, it is first removed."
pulldom.py is patched to use the public minidom interface instead
of setting .parentNode itself. Possibly this reduces pulldom's
efficiency; someone else will have to pronounce on that.
Make Node inherit from xml.dom.Node to pick up the NodeType values
defined by the W3C recommendation.
When raising AttributeError, be sure to provide the name of the attribute
that does not exist.
Node.normalize(): Make sure we do not allow an empty text node to survive
as the first child; update the sibling links properly.
_getElementsByTagNameNSHelper(): Make recursive calls using the right
number of parameters.
Attr.__setattr__(): Be sure to update name and nodeName at the same time
since they are synonyms for this node type.
AttributeList: Renamed to NamedNodeMap (AttributeList maintained as an
alias). Compute the length attribute dynamically to allow
the underlying structures to mutate.
AttributeList.item(): Call .keys() on the dictionary rather than using
self.keys() for performance.
AttributeList.setNamedItem(), .setNamedItemNS():
Added methods.
Text.splitText():
Added method.
DocumentType:
Added implementation class.
DOMImplementation:
Added implementation class.
Document.appendChild(): Do not allow a second document element to be added.
Document.documentElement: Find this dynamically, so that one can be
removed and another added.
Document.unlink(): Clear the doctype attribute.
_get_StringIO(): Only use the StringIO module; cStringIO does not support
Unicode.
objects; uses minidom if one is not provided to the constructor.
parse(): Pick up the default_bufsize default value dynamically so that
the value in the module may be (meaningfully) changed at runtime.
This (partially) closes patch #102477.