UOF.Schemas.XML (uof_schemas v0.2.0)

Copy Markdown View Source

Generic XML -> Ecto embedded schema decoder.

Parses an XML document with Saxy and, driven purely by the target schema's Ecto reflection, builds a (possibly deeply nested) params map that is cast through the schema's changeset. Because the generated schemas mirror the XSD nesting, every XML element/attribute name lines up with a schema field name, so one recursive walk handles all of them.

Call decode/1 to dispatch on the document's root element against the full generated registry (UOF.Schemas.XML.Registry) — every feed message and API response decodes through this one entry point. Use decode/2 only when you need to override that: pass a schema module to force a known type, or a custom root element => module registry to scope dispatch.

Summary

Functions

Decode xml, dispatching on its root element against the full schema registry.

Decode xml against an explicit target, overriding the default registry.

Functions

decode(xml)

Decode xml, dispatching on its root element against the full schema registry.

This is the everyday entry point: it handles every known feed message and API response. Returns {:ok, struct}, {:error, Ecto.Changeset.t()}, or {:error, {:unknown_message, name}} for an unrecognised root element.

decode(xml, target)

Decode xml against an explicit target, overriding the default registry.

target selects the schema:

  • a schema module — decode into that type (static). Use when the caller already knows it and wants to assert it regardless of the root element.
  • a registry map of root element name => schema module — dispatch on the document's root element, scoped to that map.

Returns {:ok, struct} or {:error, Ecto.Changeset.t()}; with a registry that has no entry for the root element, {:error, {:unknown_message, name}}.