Title: Theory / Unimportant / CS / Programming / Python / Lib / 20 xml / 5 etree
Tags: récupéré seen_description hasNotNewEffectReturnsMeaning FromInstruction computer_to_instruction FromVariables automatedNewLineAfterCommaSpace type mid1516974248815
On every note of this deck, unless a note says otherwise:
Page: https://docs.python.org/3/library/xml.etree.elementtree.html
Page: https://docs.python.org/3/library/xml.etree.elementtree.html

Typ: ElementTree
Meaning: An XML document as a tree
Page: https://docs.python.org/3/library/xml.etree.elementtree.html
Language: Python

Typ: Element
Meaning: A node in an ElementTree
Page: https://docs.python.org/3/library/xml.etree.elementtree.html
Language: Python
Context: XML

Instruction: ET.parse(foo)
Effect: An elementary tree from the content of document foo
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 1.2

Instruction: ET.fromstring(foo)
Effect: The root of an elementary tree from the string foo
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 1.2

Instruction: EltTr.getroot()
Effect: The Element which is the root of the tree EltTr
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 1.2
Variables: ElementTree EltTr

Variable: Elt.tag
Meaning: The tag of the element Elt
Context: import xml.etree.ElementTree as ET
Language: Python
Section: 1.2
Variables: xml element Elt

Variable: Elt.attrib
Meaning: The dictionnary of the attributes of Elt
Context: import xml.etree.ElementTree as ET
Language: Python
Section: 1.2
Variables: xml element Elt

Variable: Elt as an iterator
Meaning: The sequence of children of Elt
Context: import xml.etree.ElementTree as ET
Language: Python
Section: 1.2
Variables: xml element Elt

Variable: Elt[i]
Meaning: The \(i\)-th children of Elt
Context: import xml.etree.ElementTree as ET
Language: Python
Section: 1.2
Variables: xml element Elt

Instruction: Elt.iter(foo)
Effect: Iter on children on Elt whose tag is foo
Language: Python
Context: xml.etree.ElementTree as ET
Section: 1.3
Variables: xml element Elt

Instruction: Elt.findall(foo)
Effect: The set of children on Elt whose tag is foo (in namespace bar, optional)
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 1.3
Variables: xml element Elt

Instruction: Elt.find(
  foo,
  bar
)
Effect: The first child on Elt whose tag is foo (in namespace bar, optional)
Language: Python
Context: import xml.etree.ElementTree ET
Section: 1.3
Variables: xml element Elt

Variable: Elt.text
Meaning: The text of the element Elt
Context: import xml.etree.ElementTree as ET
Language: Python
Section: 1.5
Variables: xml element Elt

Instruction: Elt.get()
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 1.5
Returns: Attributes of Elt
Variables: xml element Elt

Instruction: Elt.set(foo,bar)
Effect: Add attribute foo with value bar to Elt
Language: Python
Context: import xml.etree.ElementTree
Section: 1.5
Variables: xml element Elt

Instruction: Elt.append(foo)
Effect: Add element foo at the end of Elt
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 1.5
Variables: xml element Elt

Instruction: EltTr.write(foo)
Effect: Write file foo with content of tree EltTr
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 1.5
Variables: xml elementTree EltTr

Instruction: Elt.remove(foo)
Effect: remove element foo from element Elt
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 1.5
Variables: xml element Elt

Instruction: todo
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 2
Variables: xml element Elt

Instruction: ET.Comment(foo)
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 3.1
Returns: An element instance representing a comment.
Extra: This factory function creates a special element that will be serialized as an XML comment by the standard serializer. The comment string can be either a bytestring or a Unicode string. foo is a string containing the comment string.

Instruction: ET.dump(foo)
Effect: Writes an element tree or element structure to sys.stdout. This function should be used for debugging only.
The exact output format is implementation dependent. In this version, it’s written as an ordinary XML file.
foo is an element tree or an individual element.
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 3.1

Instruction: ET.fromstring(foo)
Effect: Parses an XML section from a string constant. Same as XML(). foo is a string containing XML data.
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 3.1
Returns: An Element instance.

Instruction: ET.fromstringlist(
  foo,
  bar
)
Effect: Parses an XML document from a sequence of string fragments. foo is a list or other sequence containing XML data fragments.bar is an optional parser instance. If not given, the standard XMLParser parser is used.
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 3.1
Returns: An Element instance.

Instruction: ET.iselement(foo)
Effect: Checks if an object appears to be a valid element object. foo is an element instance.
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 3.1
Returns: Whether this is an element object.

Instruction: ET.iterparse(
  foo,
  bar,
  buz
)
Effect: Parses an XML section into an element tree incrementally, and reports what’s going on to the user. foo is a filename or file object containing XML data. bar is a sequence of events to report back. The supported events are the strings "start", "end", "start-ns" and "end-ns" (the “ns” events are used to get detailed namespace information). If events is omitted, only "end" events are reported. buz is an optional parser instance. If not given, the standard XMLParser parser is used. parser must be a subclass of XMLParser and can only use the default TreeBuilder as a target. Returns an iterator providing (event, elem) pairs.
Note that while iterparse() builds the tree incrementally, it issues blocking reads on source (or the file it names). As such, it’s unsuitable for applications where blocking reads can’t be made. For fully non-blocking parsing, see XMLPullParser.
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 3.1

Instruction: ET.parse(
  foo,
  bar
)
Effect: Parses an XML section into an element tree.
foo is a filename or file object containing XML data. bar is an optional parser instance.
If not given, the standard XMLParser parser is used.
Language: Python
Context: import xml.etree.ElementTree as ET
Section: 3.1
Typ: an ElementTree instance.