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

Skip to content

Commit e9af827

Browse files
committed
Cleanup the docs ElementTree a bit and describe the default_namespace parameter. In the code, replace the old outdated Doxygen-ish comment above ElementTree.write by a proper docstring.
1 parent 31efc74 commit e9af827

2 files changed

Lines changed: 21 additions & 19 deletions

File tree

Doc/library/xml.etree.elementtree.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ Functions
428428
arguments. Returns an element instance.
429429

430430

431-
.. function:: tostring(element, encoding="us-ascii", method="xml", *, \
431+
.. function:: tostring(element, encoding="us-ascii", method="xml", *,\
432432
short_empty_elements=True)
433433

434434
Generates a string representation of an XML element, including all
@@ -443,7 +443,7 @@ Functions
443443
The *short_empty_elements* parameter.
444444

445445

446-
.. function:: tostringlist(element, encoding="us-ascii", method="xml", *, \
446+
.. function:: tostringlist(element, encoding="us-ascii", method="xml", *,\
447447
short_empty_elements=True)
448448

449449
Generates a string representation of an XML element, including all
@@ -751,8 +751,9 @@ ElementTree Objects
751751
section root element.
752752

753753

754-
.. method:: write(file, encoding="us-ascii", xml_declaration=None, \
755-
method="xml", *, short_empty_elements=True)
754+
.. method:: write(file, encoding="us-ascii", xml_declaration=None,\
755+
default_namespace=None, method="xml", *,\
756+
short_empty_elements=True)
756757
757758
Writes the element tree to a file, as XML. *file* is a file name, or a
758759
:term:`file object` opened for writing. *encoding* [1]_ is the output
@@ -761,7 +762,8 @@ ElementTree Objects
761762
file. Use ``False`` for never, ``True`` for always, ``None``
762763
for only if not US-ASCII or UTF-8 or Unicode (default is ``None``).
763764
*method* is either ``"xml"``, ``"html"`` or ``"text"`` (default is
764-
``"xml"``).
765+
``"xml"``). *default_namespace* sets the default XML namespace (for
766+
"xmlns").
765767
The keyword-only *short_empty_elements* parameter controls the formatting
766768
of elements that contain no content. If *True* (the default), they are
767769
emitted as a single self-closed tag, otherwise they are emitted as a pair

Lib/xml/etree/ElementTree.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -779,26 +779,26 @@ def iterfind(self, path, namespaces=None):
779779
)
780780
return self._root.iterfind(path, namespaces)
781781

782-
##
783-
# Writes the element tree to a file, as XML.
784-
#
785-
# @def write(file, **options)
786-
# @param file A file name, or a file object opened for writing.
787-
# @param **options Options, given as keyword arguments.
788-
# @keyparam encoding Optional output encoding (default is US-ASCII).
789-
# Use "unicode" to return a Unicode string.
790-
# @keyparam method Optional output method ("xml", "html", "text" or
791-
# "c14n"; default is "xml").
792-
# @keyparam xml_declaration Controls if an XML declaration should
793-
# be added to the file. Use False for never, True for always,
794-
# None for only if not US-ASCII or UTF-8 or Unicode. None is default.
795-
796782
def write(self, file_or_filename,
797783
encoding=None,
798784
xml_declaration=None,
799785
default_namespace=None,
800786
method=None, *,
801787
short_empty_elements=True):
788+
"""Write the element tree to a file, as XML. 'file_or_filename' is a
789+
file name or a file object opened for writing. 'encoding' is the
790+
output encoding (default is US-ASCII). 'xml_declaration' controls
791+
if an XML declaration should be added to the output. Use False
792+
for never, True for always, None for only if not US-ASCII or
793+
UTF-8 or Unicode (default is None). 'method' is either "xml"
794+
(default), "html", "text" or "c14n".
795+
'default_namespace' sets the default XML namespace (for "xmlns").
796+
The keyword-only 'short_empty_elements' parameter controls the
797+
formatting of elements that contain no content. If True (default),
798+
they are emitted as a single self-closed tag, otherwise they are
799+
emitted as a pair of start/end tags.
800+
801+
"""
802802
if not method:
803803
method = "xml"
804804
elif method not in _serialize:

0 commit comments

Comments
 (0)