Davy.XML (davy v0.3.0)

Copy Markdown View Source

XML parsing and building utilities for WebDAV.

Handles namespace-aware parsing of request bodies (PROPFIND, PROPPATCH, LOCK) and generation of multistatus XML responses using Saxy.

Summary

Functions

Check whether a resolved element matches the DAV: namespace with the given local name.

Build a property element for a standard DAV: property.

Build an XML error response body.

Extract {namespace, local_name} tuples from child elements of a <prop> element.

Find the first child element matching {DAV:, local_name}.

Build a <D:lockdiscovery> element from a list of active locks.

Build a full lock response body (for LOCK method responses).

Build a complete 207 Multi-Status XML response body.

Parse an XML string into a namespace-resolved tree.

Build a <D:resourcetype> element — empty for files, contains <D:collection/> for collections.

Build a <D:response> element for a single resource.

Build the <D:supportedlock> element advertising exclusive and shared write locks.

Types

resolved_element()

@type resolved_element() ::
  {String.t(), String.t(), [{String.t(), String.t()}],
   [resolved_element() | String.t()]}

Functions

dav_element?(arg1, name)

@spec dav_element?({String.t(), String.t(), term(), term()}, String.t()) :: boolean()

Check whether a resolved element matches the DAV: namespace with the given local name.

dav_property(name, value)

@spec dav_property(String.t(), String.t() | tuple() | nil) :: Saxy.XML.element()

Build a property element for a standard DAV: property.

error_body(message)

@spec error_body(String.t()) :: iodata()

Build an XML error response body.

extract_property_names(children)

@spec extract_property_names([resolved_element() | String.t()]) :: [
  {String.t(), String.t()}
]

Extract {namespace, local_name} tuples from child elements of a <prop> element.

find_dav_child(children, local_name)

@spec find_dav_child([resolved_element() | String.t()], String.t()) ::
  resolved_element() | nil

Find the first child element matching {DAV:, local_name}.

lock_discovery_element(locks)

@spec lock_discovery_element([Davy.LockStore.lock_info()]) :: Saxy.XML.element()

Build a <D:lockdiscovery> element from a list of active locks.

lock_response(lock_info)

@spec lock_response(Davy.LockStore.lock_info()) :: iodata()

Build a full lock response body (for LOCK method responses).

multistatus(response_elements)

@spec multistatus([Saxy.XML.element()]) :: iodata()

Build a complete 207 Multi-Status XML response body.

parse(xml_string)

@spec parse(String.t()) :: {:ok, resolved_element()} | {:error, term()}

Parse an XML string into a namespace-resolved tree.

Returns {:ok, resolved_tree} or {:error, reason}. Each element becomes {namespace, local_name, attributes, children}.

resourcetype_element(atom)

@spec resourcetype_element(:file | :collection) :: Saxy.XML.element()

Build a <D:resourcetype> element — empty for files, contains <D:collection/> for collections.

response_element(href, propstats)

@spec response_element(String.t(), [
  {pos_integer(), [{String.t(), Saxy.XML.element()}]}
]) ::
  Saxy.XML.element()

Build a <D:response> element for a single resource.

propstats is a list of {status_code, [{property_name, value_element}]}.

supported_lock_element()

@spec supported_lock_element() :: Saxy.XML.element()

Build the <D:supportedlock> element advertising exclusive and shared write locks.