organoid_tracker.util.xml_wrapper module

An XML wrapper for easier parsing. It allows you to safely write code like this:

metadata[“ImageDocument”][“Metadata”][“Scaling”][“Items”][“Distance”].value_float()

If any of the elements in the chain doesn’t exist, you will just end up with None at the end, instead of crashing halfway through.

class organoid_tracker.util.xml_wrapper.XmlWrapper(element: Optional[Element])

Bases: object

An XML wrapper for easier parsing. It allows you to safely write code like this:

metadata[“ImageDocument”][“Metadata”][“Scaling”][“Items”][“Distance”].value_float()

One limitation is that you can’t extract text from elements that have both text and subelements.

attr_float(name: str) Optional[float]

Same as attr_str, but returned as a float. Returns None if the attribute was not found, or couldn’t be parsed as a float.

attr_str(name: str) Optional[str]

Returns the value of the attribute with the given name. If the attribute doesn’t exist, returns None.

is_none() bool

Checks if this element is equal to NONE_ELEMENT.

value_float() Optional[float]

If this tag has just one text node as a child, returns its value as a float. If the value is not a valid float, returns None.

value_str() Optional[str]

If this tag has just one text node as a child, returns its value. Otherwise, returns None.

organoid_tracker.util.xml_wrapper.read_xml(xml_string: str) XmlWrapper