xml
Parses, edits, validates, and serializes XML element trees.
Types
| Type | Description |
|---|---|
Attr |
XML attribute |
Node |
XML element node |
Functions
decode xml
Parses an XML document into a parentless element tree.
Parameters:
| Name | Type | Description |
|---|---|---|
xml |
Str |
XML document |
Returns: Node, the root element.
Errors:
ValueErrorif the document is invalid, has no root element, or uses an unsupported entity.
Predefined entities and numeric character references are expanded into text and attribute values. Custom DTD entities are not resolved.
encode node
Validates and serializes an XML tree.
Namespace declarations are generated from expanded names and namespace snapshots. Prefix spelling and declaration placement can differ from the input, but element and attribute namespace semantics are preserved.
Parameters:
| Name | Type | Description |
|---|---|---|
node |
Node|Str |
XML node or text |
Returns: Str, the serialized XML.
Errors:
ValueErrorif the tree is invalid or cyclic.
verify node
Checks an entire XML tree without serializing it.
Validation includes names, namespace bindings, attribute uniqueness by expanded name, child and attribute types, and cycles. A node can temporarily contain invalid data while it is being edited.
Parameters:
| Name | Type | Description |
|---|---|---|
node |
Node |
Root element |
Returns: nil.
Errors:
ValueErrorif the tree is invalid or cyclic.