Element¶
- class igwn_ligolw.ligolw.Element(attrs=None)¶
Bases:
objectBase class for all element types. This class is inspired by the class of the same name in the Python standard library’s xml.dom package. One important distinction is that the standard DOM element is used to represent the structure of a document at a much finer level of detail than here. For example, in the case of the standard DOM element, each XML attribute is its own element being a child node of its tag, while here they are simply stored as attributes of the tag element itself.
Despite the differences, the documentation for the xml.dom package, particularly that of the Element class and it’s parent, the Node class, is useful as supplementary material in understanding how to use this class.
Attributes Summary
Methods Summary
appendChild(child)Add a child to this element.
appendData(content)Add characters to the element's pcdata.
Method invoked by document parser when it encounters the end-of-element event.
end_tag(indent)Generate the string for the element's end tag.
getAttribute(attrname)getChildrenByAttributes(attrs)getElements(filter)Return a list of elements below and including this element for which filter(element) returns True.
getElementsByTagName(tagName)hasAttribute(attrname)insertBefore(newchild, refchild)Insert a new child node before an existing child.
removeAttribute(attrname)removeChild(child)Remove a child from this element.
replaceChild(newchild, oldchild)Replace an existing node with a new node.
setAttribute(attrname, value)start_tag(indent)Generate the string for the element's start tag.
unlink()Break internal references within the document tree rooted on this element to promote garbage collection.
write([fileobj, indent])Recursively write an element and it's children to a file.
Attributes Documentation
- tagName = None¶
- validchildren = frozenset({})¶
Methods Documentation
- appendChild(child)¶
Add a child to this element. The child’s parentNode attribute is updated, too.
- appendData(content)¶
Add characters to the element’s pcdata.
- endElement()¶
Method invoked by document parser when it encounters the end-of-element event.
- end_tag(indent)¶
Generate the string for the element’s end tag.
- getAttribute(attrname)¶
- getChildrenByAttributes(attrs)¶
- getElements(filter)¶
Return a list of elements below and including this element for which filter(element) returns True.
- getElementsByTagName(tagName)¶
- hasAttribute(attrname)¶
- insertBefore(newchild, refchild)¶
Insert a new child node before an existing child. It must be the case that refchild is a child of this node; if not, ValueError is raised. newchild is returned.
- removeAttribute(attrname)¶
- removeChild(child)¶
Remove a child from this element. The child element is returned, and it’s parentNode element is reset. If the child will not be used any more, you should call its unlink() method to promote garbage collection.
- replaceChild(newchild, oldchild)¶
Replace an existing node with a new node. It must be the case that oldchild is a child of this node; if not, ValueError is raised. newchild is returned.
- setAttribute(attrname, value)¶
- start_tag(indent)¶
Generate the string for the element’s start tag.
- unlink()¶
Break internal references within the document tree rooted on this element to promote garbage collection.
- classmethod validattributes()¶
- write(fileobj=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, indent='')¶
Recursively write an element and it’s children to a file.