biosimulators_utils.xml package — BioSimulators utils 0.1.154 documentation

# 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)

  Get the object(s) at an XPath

  Parameters

    - element (`etree._ElementTree`) – element tree

    - xpath (`str`) – XPath

    - namespaces (`dict`) – dictionary that maps the prefixes of namespaces to their URIs

  Returns

    object(s) at the XPath

  Return type

    `list` of `etree._ElementTree`

biosimulators_utils.xml.utils.get_attributes_of_xpaths(etree, x_paths, namespaces, attr='id')

  Determine the values of the attributes of the objects that match each XPath

  Parameters

    - etree (`lxml.etree._ElementTree`) – element tree for XML document

    - x_paths (`list` of str) – XPaths

    - namespaces (`dict`) – dictionary that maps the prefixes of namespaces to their URIs

    - attr (`str` or `dict`, 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` of `str` to `list` of `str`

biosimulators_utils.xml.utils.get_namespaces_for_xml_doc(element_tree)

  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)

  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)

  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')

  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 document

    - x_paths (`list` of str) – XPaths

    - namespaces (`dict`) – dictionary that maps the prefixes of namespaces to their URIs

    - attr (`str` or `dict`, 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` of `str` to `str`

  Raises

    ValueError – if one or more XPaths matches 0 or multiple objects