tree write(file [encoding]writes the entire contents of the tree to file file is either filename or file-like object opened for writing encoding is the output encoding to use and defaults to the interpreter default encoding if not specified ('utf- or 'asciiin most casescreating elements the types of elements held in an elementtree are represented by instances of varying types that are either created internally by parsing file or with the following construction functionscomment([text]creates new comment element text is string or byte string containing the element text this element is mapped to xml comments when parsing or writing output element(tag [attrib [**extra]]creates new element tag is the name of the element name for exampleif you were creating an element 'tag would be 'fooattrib is dictionary of element attributes specified as strings or byte strings any extra keyword arguments supplied in extra are also used to set element attributes fromstring(textcreates an element from fragment of xml text in text--the same as xml(described next processinginstruction(target [text]creates new element corresponding to processing instruction target and text are both strings or byte strings when mapped to xmlthis element corresponds to 'subelement(parenttag [attrib [**extra]]the same as element()but it automatically adds the new element as child of the element in parent xml(textcreates an element by parsing fragment of xml code in text for exampleif you set text to 'this will create standard element with tag of 'fooxmlid(textthe same as xml(textexcept that 'idattributes are collected and used to build dictionary mapping id values to elements returns tuple (elemidmapwhere elem is the new element and idmap is the id mapping dictionary for examplexmlid('hello'returns ({' '' '} lib fl ff