xsdata.formats.dataclass.models.generics module

class xsdata.formats.dataclass.models.generics.AnyElement(qname=None, text=None, tail=None, ns_map=<factory>, children=<factory>, attributes=<factory>)[source]

Bases: object

Generic ElementNode dataclass to bind xml document data to wildcard fields.

Parameters
  • qname (Optional[QName]) – qualified name with namespace.

  • text (Optional[str]) – text content.

  • tail (Optional[str]) – tail content.

  • ns_map (Dict) – prefix to namespace map.

  • children (List[object]) – children element.

  • attributes (Dict) – element attributes.

qname: Optional[lxml.etree.QName] = None
text: Optional[str] = None
tail: Optional[str] = None
ns_map: Dict
children: List[object]
attributes: Dict
class xsdata.formats.dataclass.models.generics.Namespaces[source]

Bases: object

Namespaces container used during parsing or generating xml documents.

Parameters
  • data – Namespace to prefixes map

  • auto_ns – Current auto increment prefix id

  • _ns_map – Prefix to namespace cache auto generated if the data change.

data: Dict
auto_ns: int
property prefixes

Return the list of prefixes.

Return type

List[str]

property ns_map

Return the prefix to namespace map.

Return type

Dict

prefix(namespace)[source]

Return the prefix for the given namespace.

Parameters

namespace (str) –

Return type

Optional[str]

add(uri, prefix=None)[source]

Add the given uri and optional prefix to the data storage.

If the prefix is missing and the uri exists in the storage skip the process.

If the namespace is one of the common use the predefined prefix to follow the lxml convention.

If the prefix is none assign the next auto increment prefix ns0,ns1,ns2 …

Parameters
add_all(ns_map)[source]

Shortcut method to all multiple namespaces/prefixes.

If prefix is none set the prefix to an empty string as it’s the convention for the default namespace.

Parameters

ns_map (Dict) –

clear()[source]

Clear the data storage and ns map cache.

register()[source]

Register the current namespaces map to lxml global registry.

unregister()[source]

Remove from lxml global registry the current namespaces map.