biosimulators_utils.xml package#
Submodules#
biosimulators_utils.xml.utils module#
Utilities for working with XML documents
- Author:
Jonathan Karr <karr@mssm.edu>
- Date:
2020-12-13
- Copyright:
2020, Center for Reproducible Biomedical Modeling
- License:
MIT
- biosimulators_utils.xml.utils.eval_xpath(element, xpath, namespaces)[source]#
Get the object(s) at an XPath
- Parameters:
element (
etree._ElementTree
) – element treexpath (
str
) – XPathnamespaces (
dict
) – dictionary that maps the prefixes of namespaces to their URIs
- Returns:
object(s) at the XPath
- Return type:
list
ofetree._ElementTree
- biosimulators_utils.xml.utils.get_attributes_of_xpaths(etree, x_paths, namespaces, attr='id')[source]#
Determine the values of the attributes of the objects that match each XPath
- Parameters:
etree (
lxml.etree._ElementTree
) – element tree for XML documentx_paths (
list
of str) – XPathsnamespaces (
dict
) – dictionary that maps the prefixes of namespaces to their URIsattr (
str
ordict
, optional) – attribute to get values of
- Returns:
- dictionary that maps each XPath to the
values of the attribute of the objects in the XML file that match the XPath
- Return type:
dict
ofstr
tolist
ofstr
- biosimulators_utils.xml.utils.get_namespaces_for_xml_doc(element_tree)[source]#
Get the namespaces used by an XML document
- Parameters:
et (
etree._ElementTree
)- Returns:
dictionary that maps the id of each namespace to its URI
- Return type:
dict
- biosimulators_utils.xml.utils.get_namespaces_for_xml_element(element_tree)[source]#
Get the namespaces used by an XML document
- Parameters:
et (
etree._ElementTree
)- Returns:
dictionary that maps the id of each namespace to its URI
- Return type:
dict
- biosimulators_utils.xml.utils.get_namespaces_with_prefixes(namespaces)[source]#
Get a dictionary of namespaces less namespaces that have no prefix
- Parameters:
namespaces (
dict
) – dictionary that maps prefixes of namespaces their URIs- Returns:
dictionary that maps prefixes of namespaces their URIs
- Return type:
dict
- biosimulators_utils.xml.utils.validate_xpaths_ref_to_unique_objects(etree, x_paths, namespaces, attr='id')[source]#
Validate that each of a list of XPaths matches a single object in an XML file.
- Parameters:
etree (
lxml.etree._ElementTree
) – element tree for XML documentx_paths (
list
of str) – XPathsnamespaces (
dict
) – dictionary that maps the prefixes of namespaces to their URIsattr (
str
ordict
, optional) – attribute to get values of
- Returns:
- dictionary that maps each XPath to the
value of the attribute of the object in the XML file that matches the XPath
- Return type:
dict
ofstr
tostr
- Raises:
ValueError – if one or more XPaths matches 0 or multiple objects