gws.lib.xmlx.tag

XML builder.

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.

Tag and attribute names are local names, Clark names ({uri}name) or ID:name, where ID is the name of a well-known namespace (GML, OWS_11), which is resolved to a Clark name.

Example:

tag('geometry/GML:Point', {'GML:id': 'xy'}, tag('GML:coordinates', '12.345,56.789'), srsName=3857)
Parameters:
  • name – Tag name, or a slash-separated list of tag names, in which case nested elements are created. Slashes inside the {uri} part of a Clark name do not separate.

  • *args – Content of the innermost element. A string, number, bool, date or datetime is appended to the text, an XmlElement is appended as a child, a dict or a gws.Data object updates the attributes (None values are skipped), None is ignored, and any other iterable is processed item by item with the same rules.

  • **kwargs – Additional attributes of the innermost element.

Returns:

The outermost element.

Raises:

BuildError – If a tag name is empty, a namespace ID is unknown, or an argument cannot be used.