util.persistence.serializeXML3 module

The XML3 strategy: XML2’s compact objects, in a document with a head (see SerializationStrategy.tostring()):

<?xml version='1.0' encoding='utf-8'?>
<document>
  <head>
    <property key="format" value="XML3" />
    <property key="formatVersion" value="1.0" />
    ...
    <property key="type" value="sn.model.model.Model" />
    <property key="url" value="file:///Users/me/family.snm" />
    <property key="objects" type="int" value="137" />
    <property key="superDBs" type="list">
      <item value="sn:/sn" />
      <item value="sn:/baseRules" />
    </property>
    ...
  </head>
  <object type="sn.model.model.Model" id="1"> ... </object>
</document>

The head is plain: each property’s value is a string (type “str”, left out), an int, a float, a bool, a list of those (item tags), or a table of them (property tags). It can be read without reading the rest of the file (see readHead()). Documents written by the XML and XML2 strategies (an object at the top) are read too.

Created on Oct 12, 2026

Code author: Rob Kremer <robkremer@me.com>

util.persistence.serializeXML3.TAG_DOCUMENT = 'document'

The top tag of a document.

util.persistence.serializeXML3.TAG_HEAD = 'head'

Its head’s tag.

util.persistence.serializeXML3.TAG_ITEM = 'item'

An item of a list in the head.

class util.persistence.serializeXML3.XML3SerializationStrategy

Bases: XML2SerializationStrategy

XML2’s compact objects in a document with a head (see the module doc): the default strategy.

preferred: bool = True

Chosen for the “.xml” extension (it reads what XML and XML2 write, too).

classmethod protocolName() → str
Returns:

Return type:

str

classmethod protocolVersion() → str
Returns:

Return type:

str

classmethod sniff(start: bytes) → int
Returns:

2 for a document of this format (it starts with a document tag), 1 for another XML file.

classmethod _headValue(key: str | None, value: str | int | float | bool | list | dict, tag: str = 'property') → Element
Returns:

value (see HeadValue) as a tag: a property of the head (or an item of a list, or a table, in it).

classmethod _fromHeadValue(elem: Element) → str | int | float | bool | list | dict
Returns:

The value of a tag made by _headValue().

_abc_impl = <_abc._abc_data object>
classmethod _head(elem: Element) → dict[str, str | int | float | bool | list | dict]
Returns:

The values in a head tag.

_tostringDocument(head: dict[str, str | int | float | bool | list | dict], body: Element, kwargs: dict[str, Any]) → str

Write a document (see tostring()). By default, as a table of two entries, head first: HEAD (a table of the head’s values) and BODY. A strategy may write it its own way (eg: two values one after another; see XML3SerializationStrategy), so long as _fromstringDocument() reads it, and the head comes first.

Parameters:
  • head (dict[str, HeadValue])

  • body (T) – The document’s object, encoded.

  • kwargs (dict[str, Any])

Returns:

Return type:

str

_documentParts(top: Element) → tuple[dict[str, str | int | float | bool | list | dict], Element]
Parameters:

top (T) – The top of a document read with _fromstring().

Returns:

Its head, and its object (still encoded): see _fromstringDocument().

Return type:

tuple[dict[str, HeadValue], T]

readHead(url: str, mode: str = '', **kwargs) → dict[str, str | int | float | bool | list | dict]

Only the start of the document is read: up to the end of its head. (A document written by XML or XML2 is read as they would be.)