5.8. yapydata.datatree.synxml

5.8.1. Module

The YapyData.xml module provides XML.

Sources: yapydata/datatree/synxml.py

5.8.2. Functions

5.8.2.1. readout_data

synxml.readout_data(**kargs)

Scan tree into JSON representation. Uses recursive calls to readout_data through the logical tree spanned by xml.etree.

Parameters
  • xval – The input tree as received from xml.etree.cElementTree.

  • kargs

    striproot:

    Strips the root node. The named root node is mandatory due to the standard of W3C. Common other syntaxes such as JSON, YAML, and INI do not have unique baned root nodes at all. The striproot parameter removes the name root node, thus makes the structure of the scanned data tree compatible to the other syntax representations.

    striproot := (
          True    # the named root node is removed
        | False   # the named root node is preserved
    )
    
    default := False
    

    The parameter is processed in the first call of the recursion only, thus not passed to further calls.

Returns

The resulting scanned data structure.

Raises

pass-through

5.8.3. DataTreeXML

class yapydata.datatree.synxml.DataTreeXML(data={}, **kargs)[source]

Provides XML based read-only configuration of capabilities. This in particular comprises the priority based readout of values and defaults. The structure hereby includes specialization by subcomponents, where the missing value will be tried from the more general enclosing super component.

The access to structured data trees offers various method to access paths of nested node attributes. This comprises the creation as well as the readout.

The following equivalent creation methods are supported, where ‘treenode’ could be either the root node, or any subordinated branch:

treenode['subnode0']['subnode1']['subnode7'] = value  # dynamic items

value = treenode(
            'subnode0', 'subnode1', 'subnode7',
            create=True,
        )  # dynamic items by '__call__'

value = treenode.subnode0.subnode1.subnode7           # static attribute addressing style

The following equivalent readout methods are supported, where ‘treenode’ could be either the root node, or any subordinated branch:

value = treenode['subnode0']['subnode1']['subnode7']  # dynamic items
value = treenode('subnode0', 'subnode1', 'subnode7')  # dynamic items by '__call__'
value = treenode.subnode0.subnode1.subnode7           # static attribute addressing style

5.8.3.1. __init__

DataTreeXML.__init__(data={}, **kargs)[source]
Parameters

data

A JSON compliant in-memory data tree in accordance to RFC-7159:

json-value := (
      object | array
    | number
    | string
    | false  | true
    | null
)

The equivalent Python types are - based on JSON-RFC7159 as canonical in-memory data:

RFC-7159-type-for-json := (
      dict | list            # see: object, array
    | int  | float           # see: number
    | str                    # see: unicode / for Python: ISSTR = (str(3) | unicode(2))
    | None | True  | False   # see: null, true, false
)

The initial data defines the permitted type of the first item within the subpath of the spanned data tree.

Thus atomic data types define a single node data tree only - new in RFC-7159.

Returns

None / initialized object

Raises

5.8.3.2. __setattr__

DataTreeXML.__setattr__(name, value)[source]

Validates types of own data attributes.

Parameters
  • name

    Name of the attribute. Following are reserved and treated special:

    • type: str - ‘data’ The value is treated as the replacement of the internal data attribute. Replaces or creates the complete data of teh current instance.

  • value – The value of the attribute. This by default superposes present values by replacement. Non-present are created.

Returns:

Raises

YapyDataDataTreeError

5.8.3.3. isvalid_top

static DataTreeXML.isvalid_top(value, **kargs)[source]

NOP

5.8.3.4. import_data

DataTreeXML.import_data(fpname, key=None, node=None, **kargs)[source]

Reads a XML file. This is a simple basic method for the application on the lower layers of the software stack. It is designed for minimal dependencies. The used library is the standard xml.etree library, so in the current first release DOM based. The data is by not validated.

Parameters
  • fpname

    File path name of the XML file.

    fpname := <xml-file-path-name>
    xml-file-path-name := (
          <file-path-name>           # with extension
        | <file-path-name> '.xml'   # without extension, for multiple syntaxes
    )
    

  • key

    The key for the insertion point:

    node[key] = <file-data>
    
    default := None - replace self.data,
    

    The caller is responsible for the containment of the provided node within the data structure represented by this object. No checks are performed.

  • node

    The node for the insertion of the read data.:

    default := <top>
    

  • kargs

    striproot:

    Strips the root node. The named root node is mandatory due to the standard of W3C. Common other syntaxes such as JSON, YAML, and INI do not have unique baned root nodes at all. The striproot parameter removes the name root node, thus makes the structure of the scanned data tree compatible to the other syntax representations.

    striproot := (
          True    # the named root node is removed
        | False   # the named root node is preserved
    )
    
    default := False
    

    The parameter is processed in the first call of the recursion only, thus not passed to further calls.

Returns

Reference to read data structure.

Raises
  • YapyDataConfigError

  • pass-through

5.8.3.5. strtotype

static DataTreeXML.strtotype(cdatain)[source]

Provides optional automatic type cast for basic atomic types and keywords by basic heuristics.

For advanced generic type casts use e.g. XMLschema.

Parameters

cdatain

Character data input. The value eventually representing a known non-string type. Supported conversions are:

known-types := (
      int         # integer: [+-][0-9]+
    | float       # float:   [+-][0-9]+[.][0-9]+
    | null        # None:    null
    | true        # True:    true
    | false       # False:   false
)

The applicable container type object is provided by the document structure, the type array is implemented within readout_data.

Returns

Converted input, or raw input for unknown.

Raises

pass-throuhg

5.8.4. Exceptions

exception yapydata.datatree.synxml.YapyDataXMLError[source]

Common XML syntax error.