parse_xml()

Build documents from inline XML.

Usage

Source

parse_xml(
    content,
    *,
    tag=None,
    type_attr="type",
    ref_attr="ref",
    document_tag=None,
    segment_tags=(),
    exclude_tags=()
)

Content without a single root element (an inline fragment, as a model would write it) is one document. A <documents> root, as write_xml writes, holds <document id=…>s.

Parameters

content: str

The XML text.

tag: str | None = None

The annotation element name; None means every element is an annotation named by its label.

type_attr: str = "type"

With tag, the attribute holding the label.

ref_attr: str = "ref"

The attribute linking the elements of one entity (space-separated values put one element into several entities).

document_tag: str | None = None

Each element with this name is one document (e.g. "article").

segment_tags: Sequence[str] = ()

Structural elements to keep as segments of that kind (e.g. sentences).

exclude_tags: Sequence[str] = ()
Structural elements whose text is not part of the document text; their text is kept in metadata[name].