summaryrefslogtreecommitdiff
path: root/Doc/library/xml.etree.elementtree.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/xml.etree.elementtree.rst')
-rw-r--r--Doc/library/xml.etree.elementtree.rst26
1 files changed, 13 insertions, 13 deletions
diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst
index 488cf4eeec..f5cdf0371e 100644
--- a/Doc/library/xml.etree.elementtree.rst
+++ b/Doc/library/xml.etree.elementtree.rst
@@ -94,7 +94,7 @@ As an :class:`Element`, ``root`` has a tag and a dictionary of attributes::
It also has children nodes over which we can iterate::
>>> for child in root:
- ... print(child.tag, child.attrib)
+ ... print(child.tag, child.attrib)
...
country {'name': 'Liechtenstein'}
country {'name': 'Singapore'}
@@ -143,8 +143,8 @@ elements, call :meth:`XMLPullParser.read_events`. Here is an example::
[('start', <Element 'mytag' at 0x7fa66db2be58>)]
>>> parser.feed(' more text</mytag>')
>>> for event, elem in parser.read_events():
- ... print(event)
- ... print(elem.tag, 'text=', elem.text)
+ ... print(event)
+ ... print(elem.tag, 'text=', elem.text)
...
end
@@ -166,7 +166,7 @@ the sub-tree below it (its children, their children, and so on). For example,
:meth:`Element.iter`::
>>> for neighbor in root.iter('neighbor'):
- ... print(neighbor.attrib)
+ ... print(neighbor.attrib)
...
{'name': 'Austria', 'direction': 'E'}
{'name': 'Switzerland', 'direction': 'W'}
@@ -180,9 +180,9 @@ with a particular tag, and :attr:`Element.text` accesses the element's text
content. :meth:`Element.get` accesses the element's attributes::
>>> for country in root.findall('country'):
- ... rank = country.find('rank').text
- ... name = country.get('name')
- ... print(name, rank)
+ ... rank = country.find('rank').text
+ ... name = country.get('name')
+ ... print(name, rank)
...
Liechtenstein 1
Singapore 4
@@ -206,9 +206,9 @@ Let's say we want to add one to each country's rank, and add an ``updated``
attribute to the rank element::
>>> for rank in root.iter('rank'):
- ... new_rank = int(rank.text) + 1
- ... rank.text = str(new_rank)
- ... rank.set('updated', 'yes')
+ ... new_rank = int(rank.text) + 1
+ ... rank.text = str(new_rank)
+ ... rank.set('updated', 'yes')
...
>>> tree.write('output.xml')
@@ -244,9 +244,9 @@ We can remove elements using :meth:`Element.remove`. Let's say we want to
remove all countries with a rank higher than 50::
>>> for country in root.findall('country'):
- ... rank = int(country.find('rank').text)
- ... if rank > 50:
- ... root.remove(country)
+ ... rank = int(country.find('rank').text)
+ ... if rank > 50:
+ ... root.remove(country)
...
>>> tree.write('output.xml')