xml.etree.ElementTree.parse()

xml.etree.ElementTree.parse(source, parser=None) Parses an XML section into an element tree. source is a filename or file object containing XML data. parser is an optional parser instance. If not given, the standard XMLParser parser is used. Returns an ElementTree instance.

xml.etree.ElementTree.ParseError

class xml.etree.ElementTree.ParseError XML parse error, raised by the various parsing methods in this module when parsing fails. The string representation of an instance of this exception will contain a user-friendly error message. In addition, it will have the following attributes available: code A numeric error code from the expat parser. See the documentation of xml.parsers.expat for the list of error codes and their meanings. position A tuple of line, column numbers, specifying

xml.etree.ElementTree.iselement()

xml.etree.ElementTree.iselement(element) Checks if an object appears to be a valid element object. element is an element instance. Returns a true value if this is an element object.

xml.etree.ElementTree.iterparse()

xml.etree.ElementTree.iterparse(source, events=None, parser=None) Parses an XML section into an element tree incrementally, and reports what’s going on to the user. source is a filename or file object containing XML data. events 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. parser is an optional parser i

xml.etree.ElementTree.ParseError.position

position A tuple of line, column numbers, specifying where the error occurred.

xml.etree.ElementTree.fromstring()

xml.etree.ElementTree.fromstring(text) Parses an XML section from a string constant. Same as XML(). text is a string containing XML data. Returns an Element instance.

xml.etree.ElementTree.fromstringlist()

xml.etree.ElementTree.fromstringlist(sequence, parser=None) Parses an XML document from a sequence of string fragments. sequence is a list or other sequence containing XML data fragments. parser is an optional parser instance. If not given, the standard XMLParser parser is used. Returns an Element instance. New in version 3.2.

xml.etree.ElementTree.ElementTree._setroot()

_setroot(element) Replaces the root element for this tree. This discards the current contents of the tree, and replaces it with the given element. Use with care. element is an element instance.

xml.etree.ElementTree.ElementTree.parse()

parse(source, parser=None) Loads an external XML section into this element tree. source is a file name or file object. parser is an optional parser instance. If not given, the standard XMLParser parser is used. Returns the section root element.

xml.etree.ElementTree.ElementTree.write()

write(file, encoding="us-ascii", xml_declaration=None, default_namespace=None, method="xml", *, short_empty_elements=True) Writes the element tree to a file, as XML. file is a file name, or a file object opened for writing. encoding [1] is the output encoding (default is US-ASCII). xml_declaration controls if an XML declaration should be added to the file. Use False for never, True for always, None for only if not US-ASCII or UTF-8 or Unicode (default is None). default_namespace sets the def