xml
Parses, edits, and serializes XML documents.
Types
| Type | Description |
|---|---|
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
| Name | Type | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
document |
Document |
Errors
EncodeError if an element contains itself.