Skip to content

xml

django_spire.contrib.sync.file.reader.xml

XmlField dataclass

key instance-attribute

path instance-attribute

cast = str class-attribute instance-attribute

default = '' class-attribute instance-attribute

XmlListField dataclass

key instance-attribute

path instance-attribute

XmlReader

Bases: Reader

Source code in django_spire/contrib/sync/file/reader/xml.py
def __init__(
    self,
    record_path: str,
    fields: list[XmlField | XmlListField],
) -> None:
    self._fields: list[XmlField] = []
    self._list_fields: list[XmlListField] = []
    self._record_path = record_path

    for f in fields:
        if isinstance(f, XmlListField):
            self._list_fields.append(f)
        else:
            self._validate_field_default(f)
            self._fields.append(f)

read

Source code in django_spire/contrib/sync/file/reader/xml.py
def read(self, file_path: str | Path) -> list[dict[str, Any]]:
    tree = DefusedET.parse(Path(file_path))
    root = tree.getroot()

    return [
        self._parse_record(element)
        for element in root.findall(self._record_path)
    ]