Skip to content

Commit dcbb0fb

Browse files
gh-155631: Document the CharacterData interface and other DOM members
CharacterData was not mentioned at all, although Text, Comment and CDATASection inherit from it. Also document members which are implemented, but were omitted: Node.ownerDocument, Node.isSupported(), Node.getUserData(), Node.setUserData(), Document.doctype, Document.implementation, Document.documentURI, Document.strictErrorChecking, Document.createDocumentFragment(), Document.createCDATASection(), Document.importNode(), Document.renameNode(), Element.setIdAttribute(), Element.setIdAttributeNS(), Element.setIdAttributeNode(), Attr.isId, Attr.ownerElement, Text.wholeText, Text.splitText() and Text.replaceWholeText().
1 parent b11e749 commit dcbb0fb

1 file changed

Lines changed: 188 additions & 4 deletions

File tree

Doc/library/xml.dom.rst

Lines changed: 188 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,34 @@ All of the components of an XML document are subclasses of :class:`Node`.
314314
``None``. This is a read-only attribute.
315315

316316

317+
.. attribute:: Node.ownerDocument
318+
319+
The :class:`Document` object to which this node belongs, or ``None``
320+
for a document itself.
321+
This is a read-only attribute.
322+
323+
324+
.. method:: Node.isSupported(feature, version)
325+
326+
Return whether the DOM implementation supports a particular *feature*,
327+
as :meth:`DOMImplementation.hasFeature` does.
328+
329+
330+
.. method:: Node.setUserData(key, data, handler)
331+
332+
Associate *data* with *key* on this node and return the data previously
333+
associated with *key*, or ``None``.
334+
If *data* is ``None``, the association is removed.
335+
*handler* is called when the node is cloned, imported, renamed or deleted;
336+
pass ``None`` if no notification is needed.
337+
338+
339+
.. method:: Node.getUserData(key)
340+
341+
Return the data associated with *key* on this node
342+
by :meth:`~Node.setUserData`, or ``None``.
343+
344+
317345
.. attribute:: Node.nodeName
318346

319347
This has a different meaning for each node type; see the DOM specification for
@@ -509,6 +537,46 @@ inherits properties from :class:`Node`.
509537
The one and only root element of the document.
510538

511539

540+
.. attribute:: Document.doctype
541+
542+
The :class:`DocumentType` node of the document, or ``None``.
543+
This is a read-only attribute.
544+
545+
546+
.. attribute:: Document.implementation
547+
548+
The :class:`DOMImplementation` object which created this document.
549+
This is a read-only attribute.
550+
551+
552+
.. attribute:: Document.strictErrorChecking
553+
554+
Whether error checking is enforced.
555+
Always ``False`` in :mod:`xml.dom.minidom`.
556+
557+
558+
.. attribute:: Document.documentURI
559+
560+
The location of the document, or ``None`` if it is unknown.
561+
562+
563+
.. method:: Document.createDocumentFragment()
564+
565+
Create and return an empty :class:`DocumentFragment` node.
566+
567+
568+
.. method:: Document.createCDATASection(data)
569+
570+
Create and return a :class:`CDATASection` node containing *data*.
571+
572+
573+
.. method:: Document.importNode(importedNode, deep)
574+
575+
Return a copy of *importedNode* which belongs to this document.
576+
The original node is not removed from its document.
577+
If *deep* is true, the descendants of the node are copied too.
578+
579+
512580
.. method:: Document.createElement(tagName)
513581

514582
Create and return a new element node. The element is not inserted into the
@@ -574,6 +642,18 @@ inherits properties from :class:`Node`.
574642
namespace after the prefix.
575643

576644

645+
.. method:: Document.renameNode(n, namespaceURI, name)
646+
647+
Rename the element or attribute node *n*
648+
and return it.
649+
*namespaceURI* is the new namespace URI, or
650+
:data:`~xml.dom.EMPTY_NAMESPACE` if the node does not belong to a namespace.
651+
*name* is the new qualified name.
652+
653+
Raise :exc:`WrongDocumentErr` if *n* was created by other document,
654+
and :exc:`NotSupportedErr` if it is neither an element nor an attribute.
655+
656+
577657
.. _dom-element-objects:
578658

579659
Element Objects
@@ -589,6 +669,25 @@ of that class.
589669
The value is a string.
590670

591671

672+
.. method:: Element.setIdAttribute(name)
673+
674+
Declare that the attribute *name* is of type ID,
675+
so that the element is found by :meth:`Document.getElementById`.
676+
Raise :exc:`NotFoundErr` if the element has no such attribute.
677+
678+
679+
.. method:: Element.setIdAttributeNS(namespaceURI, localName)
680+
681+
The same as :meth:`~Element.setIdAttribute`,
682+
but for an attribute specified by its namespace URI and local name.
683+
684+
685+
.. method:: Element.setIdAttributeNode(idAttr)
686+
687+
The same as :meth:`~Element.setIdAttribute`,
688+
but for an already retrieved attribute node.
689+
690+
592691
.. method:: Element.getElementsByTagName(tagName)
593692

594693
Same as equivalent method in the :class:`Document` class.
@@ -705,6 +804,21 @@ Attr Objects
705804
empty string.
706805

707806

807+
.. attribute:: Attr.isId
808+
809+
Whether this attribute is of type ID,
810+
either because it is declared as such in the DTD
811+
or because :meth:`Element.setIdAttribute` was used.
812+
This is a read-only attribute.
813+
814+
815+
.. attribute:: Attr.ownerElement
816+
817+
The :class:`Element` node to which this attribute belongs,
818+
or ``None`` if it is not used.
819+
This is a read-only attribute.
820+
821+
708822
.. attribute:: Attr.value
709823

710824
The text value of the attribute. This is a synonym for the
@@ -735,13 +849,63 @@ You can use them or you can use the standardized :meth:`!getAttribute\*` family
735849
of methods on the :class:`Element` objects.
736850

737851

852+
.. _dom-characterdata-objects:
853+
854+
CharacterData Objects
855+
^^^^^^^^^^^^^^^^^^^^^
856+
857+
:class:`CharacterData` represents text-like data in the XML document.
858+
It is a subclass of :class:`Node`, and the base class
859+
of :class:`Text`, :class:`CDATASection` and :class:`Comment`.
860+
Such nodes cannot have child nodes.
861+
862+
863+
.. attribute:: CharacterData.data
864+
865+
The content of the node as a string.
866+
867+
868+
.. attribute:: CharacterData.length
869+
870+
The number of characters in :attr:`~CharacterData.data`.
871+
This is a read-only attribute.
872+
873+
874+
.. method:: CharacterData.substringData(offset, count)
875+
876+
Return the substring of :attr:`~CharacterData.data`
877+
of *count* characters starting at *offset*.
878+
879+
880+
.. method:: CharacterData.appendData(arg)
881+
882+
Append the string *arg* to :attr:`~CharacterData.data`.
883+
884+
885+
.. method:: CharacterData.insertData(offset, arg)
886+
887+
Insert the string *arg* into :attr:`~CharacterData.data` at *offset*.
888+
889+
890+
.. method:: CharacterData.deleteData(offset, count)
891+
892+
Remove *count* characters from :attr:`~CharacterData.data`
893+
starting at *offset*.
894+
895+
896+
.. method:: CharacterData.replaceData(offset, count, arg)
897+
898+
Replace *count* characters of :attr:`~CharacterData.data`
899+
starting at *offset* with the string *arg*.
900+
901+
738902
.. _dom-comment-objects:
739903

740904
Comment Objects
741905
^^^^^^^^^^^^^^^
742906

743-
:class:`Comment` represents a comment in the XML document. It is a subclass of
744-
:class:`Node`, but cannot have child nodes.
907+
:class:`Comment` represents a comment in the XML document.
908+
It is a subclass of :class:`CharacterData`.
745909

746910

747911
.. attribute:: Comment.data
@@ -762,14 +926,34 @@ enclosed in CDATA marked sections are stored in :class:`CDATASection` objects.
762926
These two interfaces are identical, but provide different values for the
763927
:attr:`nodeType` attribute.
764928

765-
These interfaces extend the :class:`Node` interface. They cannot have child
766-
nodes.
929+
These interfaces extend the :class:`CharacterData` interface.
767930

768931

769932
.. attribute:: Text.data
770933

771934
The content of the text node as a string.
772935

936+
937+
.. attribute:: Text.wholeText
938+
939+
The text of all :class:`Text` nodes logically adjacent to this node,
940+
concatenated in document order.
941+
This is a read-only attribute.
942+
943+
944+
.. method:: Text.replaceWholeText(content)
945+
946+
Replace the text of all :class:`Text` nodes logically adjacent
947+
to this node with *content*, removing the other nodes.
948+
Return this node, or ``None`` if *content* is empty.
949+
950+
951+
.. method:: Text.splitText(offset)
952+
953+
Split this node into two nodes at *offset*,
954+
keeping the first part in this node
955+
and returning a new sibling node with the rest.
956+
773957
.. note::
774958

775959
The use of a :class:`CDATASection` node does not indicate that the node

0 commit comments

Comments
 (0)