gws.lib.xmlx.tag

XML builder.

This module provides a single function tag, which creates an Xml Element from a list of arguments.

The first argument to this function is interpreted as a tag name or a space separated list of tag names, in which case nested elements are created.

The remaining *args are interpreted as follows:

  • a simple string or number value - appended to the text content of the Element

  • an Xml Element - appended as a child to the Element

  • a dict - attributes of the Element are updated from this dict

  • a list, tuple or a generator - used as arguments to tag to create a child tag

If keyword arguments are given, they are added to the Element’s attributes.

Example:

tag(
    'geometry gml:Point',
    {'gml:id': 'xy'},
    ['gml:coordinates', '12.345,56.789'],
    srsName=3857
)

creates the following element:

<geometry>
    <gml:Point gml:id="xy" srsName="3857">
        <gml:coordinates>12.345,56.789</gml:coordinates>
    </gml:Point>
</geometry>

Source code: gws.lib.xmlx.tag

Module Contents

gws.lib.xmlx.tag.tag(name: str, *args, **kwargs) gws.XmlElement

Build an XML element from arguments.

Parameters:
  • name – A tag name or names.

  • *args – A collection of args.

  • **kwargs – Additional attributes.

Returns:

An XML element.