Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eca0445

Browse files
committed
Issue #24079: Improve description of the text and tail attributes for
ElementTree Element objects. Initial patch by Martin Panter.
1 parent 5080deb commit eca0445

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

Doc/library/xml.etree.elementtree.rst

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -651,21 +651,29 @@ Element Objects
651651

652652

653653
.. attribute:: text
654+
tail
654655

655-
The *text* attribute can be used to hold additional data associated with
656-
the element. As the name implies this attribute is usually a string but
657-
may be any application-specific object. If the element is created from
658-
an XML file the attribute will contain any text found between the element
659-
tags.
656+
These attributes can be used to hold additional data associated with
657+
the element. Their values are usually strings but may be any
658+
application-specific object. If the element is created from
659+
an XML file, the *text* attribute holds either the text between
660+
the element's start tag and its first child or end tag, or ``None``, and
661+
the *tail* attribute holds either the text between the element's
662+
end tag and the next tag, or ``None``. For the XML data
660663

664+
.. code-block:: xml
661665
662-
.. attribute:: tail
666+
<a><b>1<c>2<d/>3</c></b>4</a>
663667
664-
The *tail* attribute can be used to hold additional data associated with
665-
the element. This attribute is usually a string but may be any
666-
application-specific object. If the element is created from an XML file
667-
the attribute will contain any text found after the element's end tag and
668-
before the next tag.
668+
the *a* element has ``None`` for both *text* and *tail* attributes,
669+
the *b* element has *text* ``"1"`` and *tail* ``"4"``,
670+
the *c* element has *text* ``"2"`` and *tail* ``None``,
671+
and the *d* element has *text* ``None`` and *tail* ``"3"``.
672+
673+
To collect the inner text of an element, see :meth:`itertext`, for
674+
example ``"".join(element.itertext())``.
675+
676+
Applications may store arbitrary objects in these attributes.
669677

670678

671679
.. attribute:: attrib

0 commit comments

Comments
 (0)