Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml.etree.ElementTree.Element does not catch text #68260

Closed
jlaurens mannequin opened this issue Apr 29, 2015 · 2 comments
Closed

xml.etree.ElementTree.Element does not catch text #68260

jlaurens mannequin opened this issue Apr 29, 2015 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@jlaurens
Copy link
Mannequin

jlaurens mannequin commented Apr 29, 2015

BPO 24072
Nosy @rhettinger, @scoder, @ned-deily

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2015-04-29.02:39:48.616>
created_at = <Date 2015-04-29.00:42:01.553>
labels = ['type-bug', 'invalid']
title = 'xml.etree.ElementTree.Element does not catch text'
updated_at = <Date 2015-04-29.02:39:48.603>
user = 'https://bugs.python.org/jlaurens'

bugs.python.org fields:

activity = <Date 2015-04-29.02:39:48.603>
actor = 'ned.deily'
assignee = 'none'
closed = True
closed_date = <Date 2015-04-29.02:39:48.616>
closer = 'ned.deily'
components = []
creation = <Date 2015-04-29.00:42:01.553>
creator = 'jlaurens'
dependencies = []
files = []
hgrepos = []
issue_num = 24072
keywords = []
message_count = 2.0
messages = ['242207', '242209']
nosy_count = 5.0
nosy_names = ['rhettinger', 'scoder', 'ned.deily', 'eli.bendersky', 'jlaurens']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue24072'
versions = ['Python 3.4']

@jlaurens
Copy link
Mannequin Author

jlaurens mannequin commented Apr 29, 2015

text is not catcher in case 3 below

INPUT

import xml.etree.ElementTree as ET
root1 = ET.fromstring('<a>TEXT</a>')
print(root1.text)
root2 = ET.fromstring('<a>TEXT<b/></a>')
print(root2.text)
root3 = ET.fromstring('<a><b/>TEXT</a>')
print(root3.text)

CURRENT OUTPUT

TEXT
TEXT
None <---------- ERROR HERE

EXPECTED OUTPUT

TEXT
TEXT
TEXT

@jlaurens jlaurens mannequin added the type-bug An unexpected behavior, bug, or error label Apr 29, 2015
@ned-deily
Copy link
Member

While a bit confusing, I don't think this is a bug. Note the definition of the "tail" attribute of an element:

"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."

Unlike in root1 and root2 where 'TEXT' is before the end of element a and the start of element b (in root2), 'TEXT' in root3 follows the end tag of element b and so is associated with it as its tail attribute.

>>> root3
<Element 'a' at 0x1022ab188>
>>> root3[0]
<Element 'b' at 0x1022ab1d8>
>>> root3[0].tail
'TEXT'

https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.tail

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant