fastoad.io.xml package

Subpackages

Submodules

Module contents

Package for handling XML files

class fastoad.io.xml.VariableLegacy1XmlFormatter[source]

Bases: VariableXmlBaseFormatter

Formatter for legacy XML format (version “1”)

class fastoad.io.xml.VariableXmlBaseFormatter(translator: VarXpathTranslator)[source]

Bases: IVariableIOFormatter

Customizable formatter for variables

User must provide at instantiation a VarXpathTranslator instance that tells how variable names should be converted from/to XPath.

Note: XPath are always considered relatively to the root. Therefore, “foo/bar” should be provided to match following XML structure:

<root>
    <foo>
        <bar>
            "some value"
        </bar>
    </foo>
</root>
Parameters:

translator – the VarXpathTranslator instance

xml_unit_attribute

The XML attribute key for specifying units

xml_io_attribute

The XML attribute key for specifying I/O status

read_variables(data_source: str | PathLike | IO) VariableList[source]

Reads variables from provided data source file.

Parameters:

data_source

Returns:

a list of Variable instance

write_variables(data_source: str | PathLike | IO, variables: VariableList)[source]

Writes variables to defined data source file.

Parameters:
  • data_source

  • variables

class fastoad.io.xml.VariableXmlStandardFormatter[source]

Bases: VariableXmlBaseFormatter

Standard XML formatter for variables

Assuming self.path_separator is defined as : (default), a variable named like foo:bar with units m/s will be read and written as:

<aircraft>
    <foo>
        <bar units="m/s" >`42.0</bar>
    </foo>
<aircraft>

When writing outputs of a model, OpenMDAO component hierarchy may be used by defining

self.path_separator = '.'  # Discouraged for reading !
self.use_promoted_names = False

This way, a variable like componentA.subcomponent2.my_var will be written as:

<aircraft>
    <componentA>
        <subcomponent2>
            <my_var units="m/s" >72.0</my_var>
        </subcomponent2>
    <componentA>
<aircraft>
property path_separator

The separator that will be used in OpenMDAO variable names to match XML path. Warning: The dot “.” can be used when writing, but not when reading.

read_variables(data_source: str | PathLike | IO) VariableList[source]

Reads variables from provided data source file.

Parameters:

data_source

Returns:

a list of Variable instance

write_variables(data_source: str | PathLike | IO, variables: VariableList)[source]

Writes variables to defined data source file.

Parameters:
  • data_source

  • variables