|
|
DOM Standards compliance
The Python Library Reference includes a brief chapter on the required
mappings
and conformance of Python DOM implementations.
In practice, things are a little more complicated for authors of XML
applications, because implementations in common usage do not support the full
DOM standard as defined by W3C. This is partly due to design considerations
(for example some DOMs are optimised more for speed than full compliance), and
partly — particularly in older versions — due to bugs.
This table documents places where Python DOM implementations diverge from
the W3C DOM Level 2 Core/XML specification (with Python bindings). The
xml.dom.minidom module is tested in versions from the standard Python
language distributions, and from PyXML package versions. PyXML’s more
comprehensive 4DOM implementation and 4Suite’s C-based and Python-based
Domlettes are also included.
Any issues related to doctypes, normalization, validation and serialisation have not
been tested for and are not (yet) documented here; they are not always required
by DOM applications. Failure to raise exceptions in error conditions defined by
the standard is also not recorded here, as the implementations do not generally
perform strict error checking.
If you encounter any bugs in the latest implementations
of Python DOM implementations which are not already documented here, you can
discuss them on the XML-SIG
mailing list and in the case of the Python/PyXML packages, enter them into
the PyXML
bug tracker.
Implementation |
minidom |
4DOM |
cDomlette |
pDom |
FtMD |
Package |
Python |
PyXML |
4Suite |
Version |
2.0 |
2.1 |
2.2 |
2.3 |
0.6.6 |
0.7.1 |
0.8.0 |
0.8.2 |
0.8.3 |
0.6.6 |
0.7+ |
0.11.1 |
1.0a1 |
0.11.1 |
1.0a1 |
namespace declarations |
1 2 |
2 |
3 |
3 |
3 |
3 |
3 |
3 |
3 |
4 5 |
5 |
OK |
3 |
OK |
OK |
xml: namespace |
6 7 |
6 7 |
7 8 |
OK |
6 7 |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
Element namespaceURI |
9 |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
9 |
OK |
9 |
OK |
9 |
10 |
Element prefix |
9 11 |
9 11 |
11 |
OK |
9 11 |
11 |
11 |
11 |
OK |
9 |
OK |
9 |
OK |
9 |
OK |
Attr.namespaceURI |
9 |
9 |
OK |
OK |
9 |
OK |
OK |
OK |
OK |
9 |
OK |
9 |
OK |
9 |
OK |
Attr prefix |
9 11 |
9 11 |
11 |
OK |
11 12 |
11 |
11 |
11 |
OK |
9 |
OK |
9 |
OK |
9 |
OK |
Attr childNodes |
13 |
14 |
14 |
15 16 |
14 |
14 |
15 16 |
15 16 |
15 16 |
OK |
OK |
16 |
14 |
16 |
14 |
Attr specified |
- |
- |
- |
17 |
- |
- |
17 |
17 |
17 |
18 |
18 |
17 |
18 |
17 |
18 |
NodeList item, length |
- |
- |
OK |
OK |
- |
19 |
19 |
19 |
19 |
OK |
OK |
- |
- |
- |
- |
NamedNodeMap item, length |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
- |
- |
OK |
- |
NamedNodeMap getNamedItem |
- |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
20 |
20 |
- |
- |
- |
- |
NamedNodeMap getNamedItemNS |
- |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
- |
- |
- |
- |
NamedNodeMap setNamedItem |
- |
21 |
21 |
21 |
21 |
21 |
21 |
21 |
OK |
20 |
20 |
- |
- |
- |
- |
NamedNodeMap setNamedItemNS |
- |
21 22 |
21 22 |
21 22 |
21 22 |
21 22 |
21 22 |
21 22 |
22 |
OK |
OK |
- |
- |
- |
- |
NamedNodeMap removeNamedItem |
- |
- |
- |
21 23 |
- |
21 23 |
21 23 |
21 23 |
OK |
20 |
20 |
- |
- |
- |
- |
NamedNodeMap removeNamedItemNS |
- |
- |
- |
21 23 |
- |
21 23 |
21 23 |
21 23 |
OK |
OK |
OK |
- |
- |
- |
- |
CharacterData string ops |
- |
24 |
24 |
24 |
24 |
24 |
24 |
24 |
OK |
OK |
OK |
OK |
OK |
OK |
24 |
Text |
25 |
25 |
25 |
OK |
25 |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
Node previousSibling, nextSibling |
26 |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
Node nodeValue |
27 28 |
27 28 |
27 28 |
27 |
27 28 |
27 28 |
27 |
27 |
27 |
27 |
27 |
29 |
29 |
27 |
OK |
Node insertBefore |
30 |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
Document createElement, createAttribute |
31 |
31 |
31 |
31 |
31 |
31 |
31 |
31 |
31 |
OK |
OK |
- |
- |
31 |
- |
Document createElementNS, createAttributeNS |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
- |
OK |
OK |
OK |
Node hasAttributes |
- |
32 |
32 |
32 |
32 |
32 |
32 |
32 |
OK |
- |
- |
- |
- |
- |
- |
Element hasAttribute |
- |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
20 |
20 |
33 |
- |
OK |
- |
Element getAttribute |
23 |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
20 |
20 |
33 |
- |
OK |
- |
Element getAttributeNode |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
20 |
20 |
33 |
- |
OK |
- |
Element setAttribute |
21 34 |
21 34 |
21 34 |
35 |
21 34 |
21 34 |
21 34 |
35 |
35 |
20 |
20 |
- |
- |
- |
- |
Element setAttributeNode |
21 36 |
21 |
21 |
35 |
21 |
21 |
21 |
35 |
35 |
37 |
37 |
- |
- |
- |
- |
Element removeAttribute |
21 23 23 |
21 23 |
21 23 |
OK |
21 23 |
21 23 |
21 23 |
OK |
OK |
20 |
20 |
- |
- |
- |
- |
Element removeAttributeNode |
21 38 |
21 38 |
21 38 |
38 |
21 38 |
21 38 |
21 38 |
38 |
OK |
20 |
20 39 |
- |
- |
38 |
OK |
Element getAttributeNS |
23 |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
40 |
40 |
40 |
- |
Element getAttributeNodeNS |
23 |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
40 |
40 |
40 |
- |
Element setAttributeNS |
- |
21 22 34 |
21 22 34 |
35 |
21 22 34 |
21 22 34 |
21 22 34 |
35 |
35 |
OK |
OK |
- |
OK |
OK |
OK |
Element setAttributeNodeNS |
- |
21 22 |
21 22 |
35 |
21 22 |
21 22 |
21 22 |
35 |
35 |
37 |
37 |
- |
OK |
36 |
OK |
Element removeAttributeNS |
21 23 |
21 |
21 |
OK |
21 |
21 |
21 |
OK |
OK |
OK |
OK |
- |
40 |
40 |
- |
Document, Element getElementsByTagName |
41 |
41 |
41 |
41 |
41 |
41 |
41 |
41 |
41 |
41 |
41 |
- |
- |
- |
- |
Document, Element getElementsByTagNameNS |
42 |
42 |
41 |
41 |
41 |
41 |
41 |
41 |
41 |
41 |
41 |
- |
- |
- |
- |
Document getElementById |
- |
- |
- |
OK |
- |
- |
43 |
43 |
OK |
43 |
43 |
- |
- |
- |
- |
Document importNode |
- |
- |
- |
OK |
- |
- |
OK |
OK |
OK |
44 |
OK |
- |
OK |
- |
OK |
Document cloneNode |
45 |
OK |
OK |
OK |
OK |
OK |
46 |
OK |
OK |
OK |
OK |
- |
OK |
OK |
OK |
DocumentFragment |
- |
47 |
OK |
OK |
47 |
OK |
OK |
OK |
OK |
OK |
OK |
- |
OK |
OK |
OK |
DOMImplementation |
- |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
EntityReference |
- |
- |
- |
- |
- |
- |
- |
- |
- |
48 |
48 |
- |
- |
- |
- |
Comment |
49 |
49 |
49 |
OK |
49 |
49 |
49 |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
CDATASection |
- |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
OK |
- |
OK |
Compliance issues key
- no support
-
Parsing a default namespace declaration causes a TypeError.
-
Namespace declarations are not included in DOM trees resulting from
normal parsing.
-
Attribute value of an empty namespace declaration (xmlns="") is None, not
''. (Can also cause serialisation errors.)
-
For non-default namespace declarations, localName and prefix are the wrong
way round.
-
For default namespace declarations, localName and prefix are the wrong way
round.
-
xml:... attributes are not split into a prefix and localname on elements
other than the root element.
-
A KeyError is generated when parsing xml:... attributes on the root
element.
-
An IndexError is generated on parsing xml:... attributes on any element.
-
Yields '' instead of None for null values.
-
The namespaceURI of elements affected by an empty namespace declaration
is '' instead of None.
-
The prefix is not necessarily the same as in the original document that
was parsed; instead, a prefix is guessed by trying to find one that
matches the namespaceURI. If there is more than one prefix that points
to that namespaceURI, the guess could be wrong.
-
Yields empty string instead of null for default namespace declarations.
-
Yields None.
-
Yields an empty list.
-
If the attribute node has been created by setAttribute[NS] methods or
indirectly cloned, childNodes will contain an inoperable Text node
(having no 'data' property, attempts to do anything with it cause
exceptions).
-
Only read access works. In 4Suite 0.11.1’s cDomlette the childNodes are
readonly; in other DOMs changing the children puts the DOM into
an inconsistent state.
-
Always yields False.
-
Always yields True.
-
Only available when running under Python 2.2 or later.
-
Fails where the attributes have been created with namespace-aware methods
(this includes all normal parsed documents). Accessing attributes with these
methods uses a separate store for non-namespace attributes only which is
otherwise unused.
-
Attributes removed or replaced by these methods are ‘unlinked’ and have
eg. their ownerDocument properties reset to null. Unlinked nodes cannot be used again.
-
When setting an attribute, the attribute with the same nodeName
will be replaced if it exists, instead of the attribute with the same
namespaceURI and localName.
-
An exception is raised on an attempt to access a non-existant attribute,
instead of returning null or empty string or failing silently.
-
replaceData, substringData, deleteData and insertData methods
fail when the offset parameter is equal to the length of the string.
-
Document may not be parsed into normal form. There may be multiple
Text nodes next to each other.
-
Changes to the hierarchy caused by nodes being moved out when inserted
into other places are not reflected in sibling pointers.
-
Writing to nodeValue on elements where nodeValue is defined to be null
changes nodeValue, rather than leaving it as null.
-
Setting nodeValue on a ProcessingInstruction does not update the ‘data’
value (and vice versa).
-
Writing to nodeValue on elements where nodeValue is defined to be null
is disallowed.
-
insertBefore with refChild set to null doesn’t work.
-
Returns a node with localName set to its nodeName - localName should be
null.
-
Method hasAttributes is not available on all node types, only Element.
-
Never gets the attribute - always returns false for hasAttribute, empty string
for getAttribute, or null for getAttributeNode.
-
Setting an attribute with a name that already exists results in that
attribute node being replaced with a new one, instead of changing the
existing node’s value.
-
Except where setAttribute causes an existing attribute node’s value to
be changed, calling these methods will remove the attribute with the
same name or the attribute with the same namespaceURI and localName
or both, regardless of whether the NS version of the method
is being used.
-
Does not return a replaced attribute node, always returns null.
-
Trying to set an attribute node on an element that already owns
it causes an InuseAttribute error.
-
Does not return the removed attribute node, always returns null.
-
If the element has a node with the same namespaceURI and localName as the
node to be removed, but a different nodeName, the wrong attribute may
be removed; if this happens the ownerElement properties of both attributes
will be inconsistent.
-
Default namespace declarations are indexed as having a localName of
'' or None even though their localName is, correctly, ‘xmlns’. Because
None cannot be passed as a localName in cDomlette 1.0a1, default namespace
declarations become inaccessible.
-
NodeLists returned by getElementsByTagName[NS] are not ‘live’ - they
act as static lists, which do not change as the document is updated.
-
Raises TypeError.
-
Fails to match any element, returns null. minidom may in some
(namespace) circumstances cause a TypeError.
-
When an Attribute node is cloned as part of its owner element being cloned,
the clone's ownerElement property points to the original document, not the
cloner.
-
An AttributeError is raised.
-
Fails with a NameError when the node is an Attr, ProcessingInstruction, Comment,
DocumentFragment or Document, or, in ‘deep’ clone mode, when there is
a ProcessingInstruction or Comment descendant.
-
Insertion/replacement with fragments fails - only every second child
of a DocumentFragment is used.
-
Document.createEntityReference returns EntityReference objects without the
childNodes filled in. Unbound entity references always cause an error on parsing.
-
Comment objects exist but are not included in DOMs parsed from text.
|