diff options
author | Ned Deily <nad@acm.org> | 2015-08-18 02:11:17 (GMT) |
---|---|---|
committer | Ned Deily <nad@acm.org> | 2015-08-18 02:11:17 (GMT) |
commit | eca0445733acf31e9b7b38dfdeb7d9f28d2c998f (patch) | |
tree | 41701a8cd14c028b6728b3175b5795be56340824 | |
parent | 5080deb5a421da039e7108e83e7216f2e1a6638d (diff) | |
download | cpython-eca0445733acf31e9b7b38dfdeb7d9f28d2c998f.zip cpython-eca0445733acf31e9b7b38dfdeb7d9f28d2c998f.tar.gz cpython-eca0445733acf31e9b7b38dfdeb7d9f28d2c998f.tar.bz2 |
Issue #24079: Improve description of the text and tail attributes for
ElementTree Element objects. Initial patch by Martin Panter.
-rw-r--r-- | Doc/library/xml.etree.elementtree.rst | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst index eef1b58..14e5c99 100644 --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -651,21 +651,29 @@ Element Objects .. attribute:: text + tail - The *text* attribute can be used to hold additional data associated with - the element. As the name implies this attribute is usually a string but - may be any application-specific object. If the element is created from - an XML file the attribute will contain any text found between the element - tags. + These attributes can be used to hold additional data associated with + the element. Their values are usually strings but may be any + application-specific object. If the element is created from + an XML file, the *text* attribute holds either the text between + the element's start tag and its first child or end tag, or ``None``, and + the *tail* attribute holds either the text between the element's + end tag and the next tag, or ``None``. For the XML data + .. code-block:: xml - .. attribute:: tail + <a><b>1<c>2<d/>3</c></b>4</a> - The *tail* attribute can be used to hold additional data associated with - the element. This attribute is usually a string but may be any - application-specific object. If the element is created from an XML file - the attribute will contain any text found after the element's end tag and - before the next tag. + the *a* element has ``None`` for both *text* and *tail* attributes, + the *b* element has *text* ``"1"`` and *tail* ``"4"``, + the *c* element has *text* ``"2"`` and *tail* ``None``, + and the *d* element has *text* ``None`` and *tail* ``"3"``. + + To collect the inner text of an element, see :meth:`itertext`, for + example ``"".join(element.itertext())``. + + Applications may store arbitrary objects in these attributes. .. attribute:: attrib |