Skip to content

xml

Parses, edits, and serializes XML documents.

Types

TypeDescription
Comment Holds an XML comment body without markup delimiters.
DecodeError Raised when decode is given XML that is not well-formed, or that uses a feature it doesn't support.
Document Holds a complete XML document with exactly one root element.
Element An XML element: a name, attributes, and children.
EncodeError Raised when encode is given a document whose tree contains itself.
Node A child of an XML element.

Node = (Element | Comment | Str)

A child of an XML element.

Functions

decode xml -> Document

Parses a complete XML document, preserving comments and whitespace.

Predefined entities and numeric character references are expanded. Custom DTD entities are not resolved.

Parameters

NameTypeDescription
xml Str

Errors

DecodeError if the document is not well-formed XML, refers to a custom entity, or breaks a check that raises ValueError when constructing the same nodes directly.

encode document -> Str

Serializes a complete XML document.

Namespace spelling may differ while preserving expanded names.

Parameters

NameTypeDescription
document Document

Errors

EncodeError if an element contains itself.

Example

let doc = Document (Element "greeting" "hello")
assert_eq (encode doc) "<greeting>hello</greeting>"