80
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
(
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 2.7.
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
(
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 list
of events to report back. If omitted, only “end” events are reported. parser is an
optional parser instance. If not given, the standard
XMLParser
parser is used. parser is
not supported by
cElementTree
. Returns an iterator providing
(event, elem)
pairs.
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.
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.
ProcessingInstruction
(
target, text=None
)
PI element factory. This factory function creates a special element that will be
serialized as an XML processing instruction. target is a string containing the PI target.
text is a string containing the PI contents, if given. Returns an element instance,
representing a processing instruction.
xml.etree.ElementTree.
register_namespace
(
prefix, uri
)
Registers a namespace prefix. The registry is global, and any existing mapping for