Skip to content

Commit 22cf801

Browse files
gh-155631: Document the DOM constants and fix references to members
The node type constants and the exception code constants were referenced, but never documented. Document them, including ENTITY_REFERENCE_NODE, DOCUMENT_FRAGMENT_NODE and VALIDATION_ERR, which were not even mentioned, and the ValidationErr exception. Qualify references to attributes and methods with the class which defines them, so that they resolve, and refer to xml.dom.minidom for unlink(), which is not part of the DOM.
1 parent 363e3cc commit 22cf801

1 file changed

Lines changed: 98 additions & 70 deletions

File tree

Doc/library/xml.dom.rst

Lines changed: 98 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ The :mod:`!xml.dom` contains the following functions:
100100
If name is not given, this examines the available implementations to find one
101101
with the required feature set. If no implementation can be found, raise an
102102
:exc:`ImportError`. The features list must be a sequence of ``(feature,
103-
version)`` pairs which are passed to the :meth:`hasFeature` method on available
104-
:class:`DOMImplementation` objects.
103+
version)`` pairs which are passed to the :meth:`~DOMImplementation.hasFeature`
104+
method on available :class:`DOMImplementation` objects.
105105

106106
Some convenience constants are also provided:
107107

108108

109109
.. data:: EMPTY_NAMESPACE
110110

111111
The value used to indicate that no namespace is associated with a node in the
112-
DOM. This is typically found as the :attr:`namespaceURI` of a node, or used as
113-
the *namespaceURI* parameter to a namespaces-specific method.
112+
DOM. This is typically found as the :attr:`~Node.namespaceURI` of a node, or
113+
used as the *namespaceURI* parameter to a namespaces-specific method.
114114

115115

116116
.. data:: XML_NAMESPACE
@@ -137,7 +137,7 @@ exception classes. The :class:`Node` class provided by this module does not
137137
implement any of the methods or attributes defined by the DOM specification;
138138
concrete DOM implementations must provide those. The :class:`Node` class
139139
provided as part of this module does provide the constants used for the
140-
:attr:`nodeType` attribute on concrete :class:`Node` objects; they are located
140+
:attr:`~Node.nodeType` attribute on concrete :class:`Node` objects; they are located
141141
within the class rather than at the module level to conform with the DOM
142142
specifications.
143143

@@ -245,13 +245,27 @@ All of the components of an XML document are subclasses of :class:`Node`.
245245
.. attribute:: Node.nodeType
246246

247247
An integer representing the node type. Symbolic constants for the types are on
248-
the :class:`Node` object: :const:`ELEMENT_NODE`, :const:`ATTRIBUTE_NODE`,
249-
:const:`TEXT_NODE`, :const:`CDATA_SECTION_NODE`, :const:`ENTITY_NODE`,
250-
:const:`PROCESSING_INSTRUCTION_NODE`, :const:`COMMENT_NODE`,
251-
:const:`DOCUMENT_NODE`, :const:`DOCUMENT_TYPE_NODE`, :const:`NOTATION_NODE`.
248+
the :class:`Node` object.
252249
This is a read-only attribute.
253250

254251

252+
.. data:: Node.ELEMENT_NODE
253+
Node.ATTRIBUTE_NODE
254+
Node.TEXT_NODE
255+
Node.CDATA_SECTION_NODE
256+
Node.ENTITY_REFERENCE_NODE
257+
Node.ENTITY_NODE
258+
Node.PROCESSING_INSTRUCTION_NODE
259+
Node.COMMENT_NODE
260+
Node.DOCUMENT_NODE
261+
Node.DOCUMENT_TYPE_NODE
262+
Node.DOCUMENT_FRAGMENT_NODE
263+
Node.NOTATION_NODE
264+
265+
Integer constants for the possible values
266+
of the :attr:`~Node.nodeType` attribute.
267+
268+
255269
.. attribute:: Node.parentNode
256270

257271
The parent of the current node, or ``None`` for the document node. The value is
@@ -304,14 +318,14 @@ All of the components of an XML document are subclasses of :class:`Node`.
304318

305319
.. attribute:: Node.localName
306320

307-
The part of the :attr:`tagName` following the colon if there is one, else the
308-
entire :attr:`tagName`. The value is a string.
321+
The part of the :attr:`~Element.tagName` following the colon if there is one,
322+
else the entire :attr:`~Element.tagName`. The value is a string.
309323

310324

311325
.. attribute:: Node.prefix
312326

313-
The part of the :attr:`tagName` preceding the colon if there is one, else the
314-
empty string. The value is a string, or ``None``.
327+
The part of the :attr:`~Element.tagName` preceding the colon if there is one,
328+
else the empty string. The value is a string, or ``None``.
315329

316330

317331
.. attribute:: Node.namespaceURI
@@ -352,9 +366,10 @@ All of the components of an XML document are subclasses of :class:`Node`.
352366

353367
This has a different meaning for each node type; see the DOM specification for
354368
details. You can always get the information you would get here from another
355-
property such as the :attr:`tagName` property for elements or the :attr:`name`
356-
property for attributes. For all node types, the value of this attribute will be
357-
either a string or ``None``. This is a read-only attribute.
369+
property such as the :attr:`~Element.tagName` property for elements or the
370+
:attr:`~Attr.name` property for attributes. For all node types, the value of
371+
this attribute will be either a string or ``None``.
372+
This is a read-only attribute.
358373

359374

360375
.. attribute:: Node.nodeValue
@@ -407,7 +422,8 @@ All of the components of an XML document are subclasses of :class:`Node`.
407422

408423
Remove a child node. *oldChild* must be a child of this node; if not,
409424
:exc:`ValueError` is raised. *oldChild* is returned on success. If *oldChild*
410-
will not be used further, its :meth:`unlink` method should be called.
425+
will not be used further, its :meth:`~xml.dom.minidom.Node.unlink` method
426+
should be called.
411427

412428

413429
.. method:: Node.replaceChild(newChild, oldChild)
@@ -439,9 +455,9 @@ NodeList Objects
439455

440456
A :class:`NodeList` represents a sequence of nodes. These objects are used in
441457
two ways in the DOM Core recommendation: an :class:`Element` object provides
442-
one as its list of child nodes, and the :meth:`getElementsByTagName` and
443-
:meth:`getElementsByTagNameNS` methods of :class:`Node` return objects with this
444-
interface to represent query results.
458+
one as its list of child nodes, and the :meth:`~Element.getElementsByTagName`
459+
and :meth:`~Element.getElementsByTagNameNS` methods of :class:`Node` return
460+
objects with this interface to represent query results.
445461

446462
The DOM Level 2 recommendation defines one method and one attribute for these
447463
objects:
@@ -482,9 +498,9 @@ DocumentType Objects
482498
Information about the notations and entities declared by a document (including
483499
the external subset if the parser uses it and can provide the information) is
484500
available from a :class:`DocumentType` object. The :class:`DocumentType` for a
485-
document is available from the :class:`Document` object's :attr:`doctype`
501+
document is available from the :class:`Document` object's :attr:`~Document.doctype`
486502
attribute; if there is no ``DOCTYPE`` declaration for the document, the
487-
document's :attr:`doctype` attribute will be set to ``None`` instead of an
503+
document's :attr:`~Document.doctype` attribute will be set to ``None`` instead of an
488504
instance of this interface.
489505

490506
:class:`DocumentType` is a specialization of :class:`Node`, and adds the
@@ -596,15 +612,15 @@ inherits properties from :class:`Node`.
596612

597613
Create and return a new element node. The element is not inserted into the
598614
document when it is created. You need to explicitly insert it with one of the
599-
other methods such as :meth:`insertBefore` or :meth:`appendChild`.
615+
other methods such as :meth:`~Node.insertBefore` or :meth:`~Node.appendChild`.
600616

601617

602618
.. method:: Document.createElementNS(namespaceURI, tagName)
603619

604620
Create and return a new element with a namespace. The *tagName* may have a
605621
prefix. The element is not inserted into the document when it is created. You
606622
need to explicitly insert it with one of the other methods such as
607-
:meth:`insertBefore` or :meth:`appendChild`.
623+
:meth:`~Node.insertBefore` or :meth:`~Node.appendChild`.
608624

609625

610626
.. method:: Document.createTextNode(data)
@@ -632,15 +648,15 @@ inherits properties from :class:`Node`.
632648

633649
Create and return an attribute node. This method does not associate the
634650
attribute node with any particular element. You must use
635-
:meth:`setAttributeNode` on the appropriate :class:`Element` object to use the
636-
newly created attribute instance.
651+
:meth:`~Element.setAttributeNode` on the appropriate :class:`Element` object
652+
to use the newly created attribute instance.
637653

638654

639655
.. method:: Document.createAttributeNS(namespaceURI, qualifiedName)
640656

641657
Create and return an attribute node with a namespace. The *tagName* may have a
642658
prefix. This method does not associate the attribute node with any particular
643-
element. You must use :meth:`setAttributeNode` on the appropriate
659+
element. You must use :meth:`~Element.setAttributeNode` on the appropriate
644660
:class:`Element` object to use the newly created attribute instance.
645661

646662

@@ -783,17 +799,18 @@ of that class.
783799
.. method:: Element.setAttributeNode(newAttr)
784800

785801
Add a new attribute node to the element, replacing an existing attribute if
786-
necessary if the :attr:`name` attribute matches. If a replacement occurs, the
787-
old attribute node will be returned. If *newAttr* is already in use,
802+
necessary if the :attr:`~Attr.name` attribute matches. If a replacement
803+
occurs, the old attribute node will be returned. If *newAttr* is already in use,
788804
:exc:`InuseAttributeErr` will be raised.
789805

790806

791807
.. method:: Element.setAttributeNodeNS(newAttr)
792808

793809
Add a new attribute node to the element, replacing an existing attribute if
794-
necessary if the :attr:`namespaceURI` and :attr:`localName` attributes match.
795-
If a replacement occurs, the old attribute node will be returned. If *newAttr*
796-
is already in use, :exc:`InuseAttributeErr` will be raised.
810+
necessary if the :attr:`~Node.namespaceURI` and :attr:`~Attr.localName`
811+
attributes match. If a replacement occurs, the old attribute node will be
812+
returned. If *newAttr* is already in use, :exc:`InuseAttributeErr` will be
813+
raised.
797814

798815

799816
.. method:: Element.setAttributeNS(namespaceURI, qname, value)
@@ -850,7 +867,7 @@ Attr Objects
850867
.. attribute:: Attr.value
851868

852869
The text value of the attribute. This is a synonym for the
853-
:attr:`nodeValue` attribute.
870+
:attr:`~Node.nodeValue` attribute.
854871

855872

856873
.. _dom-attributelist-objects:
@@ -873,7 +890,7 @@ NamedNodeMap Objects
873890

874891
Return an attribute with a particular index. The order you get the attributes
875892
in is arbitrary but will be consistent for the life of a DOM. Each item is an
876-
attribute node. Get its value with the :attr:`value` attribute.
893+
attribute node. Get its value with the :attr:`~Attr.value` attribute.
877894

878895

879896
.. method:: NamedNodeMap.getNamedItem(name)
@@ -1019,7 +1036,7 @@ The :class:`Text` interface represents text in the XML document. If the parser
10191036
and DOM implementation support the DOM's XML extension, portions of the text
10201037
enclosed in CDATA marked sections are stored in :class:`CDATASection` objects.
10211038
These two interfaces are identical, but provide different values for the
1022-
:attr:`nodeType` attribute.
1039+
:attr:`~Node.nodeType` attribute.
10231040

10241041
These interfaces extend the :class:`CharacterData` interface.
10251042

@@ -1194,48 +1211,59 @@ attribute.
11941211
.. XXX how is this different from InvalidCharacterErr?
11951212
11961213
1214+
.. exception:: ValidationErr
1215+
1216+
Raised when an operation would make the document invalid
1217+
with respect to partial validity.
1218+
This is not known to be used in the Python DOM implementations,
1219+
but may be received from DOM implementations not written in Python.
1220+
1221+
11971222
.. exception:: WrongDocumentErr
11981223

11991224
Raised when a node is inserted in a different document than it currently belongs
12001225
to, and the implementation does not support migrating the node from one document
12011226
to the other.
12021227

1228+
12031229
The exception codes defined in the DOM recommendation map to the exceptions
12041230
described above according to this table:
12051231

1206-
+--------------------------------------+---------------------------------+
1207-
| Constant | Exception |
1208-
+======================================+=================================+
1209-
| :const:`DOMSTRING_SIZE_ERR` | :exc:`DomstringSizeErr` |
1210-
+--------------------------------------+---------------------------------+
1211-
| :const:`HIERARCHY_REQUEST_ERR` | :exc:`HierarchyRequestErr` |
1212-
+--------------------------------------+---------------------------------+
1213-
| :const:`INDEX_SIZE_ERR` | :exc:`IndexSizeErr` |
1214-
+--------------------------------------+---------------------------------+
1215-
| :const:`INUSE_ATTRIBUTE_ERR` | :exc:`InuseAttributeErr` |
1216-
+--------------------------------------+---------------------------------+
1217-
| :const:`INVALID_ACCESS_ERR` | :exc:`InvalidAccessErr` |
1218-
+--------------------------------------+---------------------------------+
1219-
| :const:`INVALID_CHARACTER_ERR` | :exc:`InvalidCharacterErr` |
1220-
+--------------------------------------+---------------------------------+
1221-
| :const:`INVALID_MODIFICATION_ERR` | :exc:`InvalidModificationErr` |
1222-
+--------------------------------------+---------------------------------+
1223-
| :const:`INVALID_STATE_ERR` | :exc:`InvalidStateErr` |
1224-
+--------------------------------------+---------------------------------+
1225-
| :const:`NAMESPACE_ERR` | :exc:`NamespaceErr` |
1226-
+--------------------------------------+---------------------------------+
1227-
| :const:`NOT_FOUND_ERR` | :exc:`NotFoundErr` |
1228-
+--------------------------------------+---------------------------------+
1229-
| :const:`NOT_SUPPORTED_ERR` | :exc:`NotSupportedErr` |
1230-
+--------------------------------------+---------------------------------+
1231-
| :const:`NO_DATA_ALLOWED_ERR` | :exc:`NoDataAllowedErr` |
1232-
+--------------------------------------+---------------------------------+
1233-
| :const:`NO_MODIFICATION_ALLOWED_ERR` | :exc:`NoModificationAllowedErr` |
1234-
+--------------------------------------+---------------------------------+
1235-
| :const:`SYNTAX_ERR` | :exc:`SyntaxErr` |
1236-
+--------------------------------------+---------------------------------+
1237-
| :const:`WRONG_DOCUMENT_ERR` | :exc:`WrongDocumentErr` |
1238-
+--------------------------------------+---------------------------------+
1232+
+---------------------------------------+---------------------------------+
1233+
| Constant | Exception |
1234+
+=======================================+=================================+
1235+
| .. data:: DOMSTRING_SIZE_ERR | :exc:`DomstringSizeErr` |
1236+
+---------------------------------------+---------------------------------+
1237+
| .. data:: HIERARCHY_REQUEST_ERR | :exc:`HierarchyRequestErr` |
1238+
+---------------------------------------+---------------------------------+
1239+
| .. data:: INDEX_SIZE_ERR | :exc:`IndexSizeErr` |
1240+
+---------------------------------------+---------------------------------+
1241+
| .. data:: INUSE_ATTRIBUTE_ERR | :exc:`InuseAttributeErr` |
1242+
+---------------------------------------+---------------------------------+
1243+
| .. data:: INVALID_ACCESS_ERR | :exc:`InvalidAccessErr` |
1244+
+---------------------------------------+---------------------------------+
1245+
| .. data:: INVALID_CHARACTER_ERR | :exc:`InvalidCharacterErr` |
1246+
+---------------------------------------+---------------------------------+
1247+
| .. data:: INVALID_MODIFICATION_ERR | :exc:`InvalidModificationErr` |
1248+
+---------------------------------------+---------------------------------+
1249+
| .. data:: INVALID_STATE_ERR | :exc:`InvalidStateErr` |
1250+
+---------------------------------------+---------------------------------+
1251+
| .. data:: NAMESPACE_ERR | :exc:`NamespaceErr` |
1252+
+---------------------------------------+---------------------------------+
1253+
| .. data:: NOT_FOUND_ERR | :exc:`NotFoundErr` |
1254+
+---------------------------------------+---------------------------------+
1255+
| .. data:: NOT_SUPPORTED_ERR | :exc:`NotSupportedErr` |
1256+
+---------------------------------------+---------------------------------+
1257+
| .. data:: NO_DATA_ALLOWED_ERR | :exc:`NoDataAllowedErr` |
1258+
+---------------------------------------+---------------------------------+
1259+
| .. data:: NO_MODIFICATION_ALLOWED_ERR | :exc:`NoModificationAllowedErr` |
1260+
+---------------------------------------+---------------------------------+
1261+
| .. data:: SYNTAX_ERR | :exc:`SyntaxErr` |
1262+
+---------------------------------------+---------------------------------+
1263+
| .. data:: VALIDATION_ERR | :exc:`ValidationErr` |
1264+
+---------------------------------------+---------------------------------+
1265+
| .. data:: WRONG_DOCUMENT_ERR | :exc:`WrongDocumentErr` |
1266+
+---------------------------------------+---------------------------------+
12391267

12401268

12411269
.. _dom-conformance:
@@ -1307,6 +1335,6 @@ considered unnecessary since the attributes are accessible directly from Python.
13071335

13081336
The IDL definitions do not fully embody the requirements of the W3C DOM API,
13091337
such as the notion of certain objects, such as the return value of
1310-
:meth:`getElementsByTagName`, being "live". The Python DOM API does not require
1311-
implementations to enforce such requirements.
1338+
:meth:`~Element.getElementsByTagName`, being "live". The Python DOM API does
1339+
not require implementations to enforce such requirements.
13121340

0 commit comments

Comments
 (0)