Python Forum
XML using xml.etree.ElementTree Question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML using xml.etree.ElementTree Question
#2
It is not a bug: the documentation says
Quote:Note iterparse() only guarantees that it has seen the “>” character of a starting tag when it emits a “start” event, so the attributes are defined, but the contents of the text and tail attributes are undefined at that point. The same applies to the element children; they may or may not be present.
If you need a fully populated element, look for “end” events instead.

Obviously, the reason is that the text has not yet been read when the iterative parser emits the start event.
Reply


Messages In This Thread
XML using xml.etree.ElementTree Question - by Ngea - Jan-10-2018, 07:20 PM
RE: XML using xml.etree.ElementTree Question - by Gribouillis - Jan-10-2018, 08:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  xml file editing with lxml.etree FlavioBueno 2 737 Jun-09-2023, 02:00 PM
Last Post: FlavioBueno
  [SOLVED] [ElementTree] Grab text in attributes? Winfried 3 1,673 May-27-2022, 04:59 PM
Last Post: Winfried
  [ElementTree] Insert big block of HTML? Winfried 0 1,206 May-12-2022, 07:08 AM
Last Post: Winfried
  ElementTree get attribute value part of string paulo79 1 2,226 Apr-05-2022, 09:13 PM
Last Post: deanhystad
  xml.etree.ElementTree question. water 0 3,325 Oct-09-2020, 06:47 PM
Last Post: water
  xml.etree.ElementTree extract string values matthias100 2 5,093 Jul-12-2020, 06:02 PM
Last Post: snippsat
  [pykml] "AttributeError: 'lxml.etree._ElementTree' object has no attribute 'Document' Winfried 3 6,678 May-26-2020, 09:30 PM
Last Post: Winfried
  Python 3 Elementtree and Comment First gw1500se 3 3,840 May-25-2020, 09:02 PM
Last Post: gw1500se
  Write the XML file from elementtree with hexa decimal encoding Dillibabu 4 3,537 Dec-24-2019, 10:10 AM
Last Post: Dillibabu
  looking for sample py to read from txt file into XML using lxml import etree venkat18 3 3,043 Jun-02-2019, 04:34 AM
Last Post: venkat18

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020