Webdavz.XmlWebDAV XML tree types and xmlm codec.
Provides a simple XML tree representation used throughout the WebDAV protocol for property values, request bodies, and multistatus responses.
The tree type models the subset of XML used by WebDAV: elements with namespace-qualified names, attributes, and text content. No support for processing instructions, comments, or mixed content — these are not used in the WebDAV wire format.
WebDAV uses XML for request bodies (PROPFIND, PROPPATCH, LOCK, REPORT) and response bodies (207 Multi-Status). All elements are namespace-qualified; the primary namespace is "DAV:" defined in RFC 4918 Section 14.
let body = Webdavz_xml.dav_node "propfind"
[dav_node "prop" [dav_node "displayname" []; dav_node "resourcetype" []]]
in
Webdavz_xml.serialize body
(* produces: <propfind xmlns="DAV:"><prop><displayname/><resourcetype/></prop></propfind> *)Fully qualified XML name: (namespace_uri, local_name).
Standard WebDAV properties use the "DAV:" namespace:
("DAV:", "displayname")CardDAV properties use:
("urn:ietf:params:xml:ns:carddav", "address-data")type attribute = fqname * stringXML attribute: (qualified_name, value).
type tree = | Pcdata of stringCharacter data (text content).
*)| Node of string * string * attribute list * tree listNode (namespace, local_name, attributes, children).
An XML element. Empty elements have children = []. Self-closing tags (e.g., <displayname/>) and explicitly closed empty tags are equivalent.
XML tree.
Recursive representation of an XML document fragment. Sufficient for all WebDAV/CardDAV wire format needs.
"DAV:" — the WebDAV namespace URI.
All standard WebDAV elements and properties are in this namespace.
val parse : string -> tree optionparse xml_string parses an XML document into a tree.
Returns the root element, or None on malformed input. Uses xmlm for standards-compliant XML 1.0 parsing with full namespace resolution.
Note: The entire document must be well-formed. Partial documents or documents with unresolved namespace prefixes will return None.
val serialize : tree -> stringserialize tree serializes a tree to an XML document string.
Includes the XML declaration (<?xml version="1.0" encoding="UTF-8"?>) as recommended by RFC 4918.
serialize (dav_node "prop" [dav_node "displayname" [pcdata "My Files"]])val serialize_compact : tree -> stringserialize_compact tree serializes without XML declaration. Suitable for embedding or tests.
http_date_of_unix_time t formats a Unix timestamp as an HTTP-date (IMF-fixdate per RFC 7231 Section 7.1.1.1): "Thu, 01 Jan 2015 00:00:00 GMT".
Used for the Webdavz_prop.getlastmodified property.
iso8601_of_unix_time t formats a Unix timestamp as ISO 8601 / RFC 3339: "2015-01-01T00:00:00Z".
Used for the Webdavz_prop.creationdate property.
val error_xml : string -> treeerror_xml element_name creates a DAV:error precondition/postcondition XML body: <D:error><D:element_name/></D:error>.
Standard error element names include:
"resource-must-be-null" — MKCOL on existing resource"propfind-finite-depth" — PROPFIND with Depth: infinity"cannot-modify-protected-property" — PROPPATCH on live propertydav_node local_name children creates an element in the "DAV:" namespace.
Equivalent to Node (dav_ns, local_name, [], children).
dav_node "href" [pcdata "/calendars/user/"]
(* = Node ("DAV:", "href", [], [Pcdata "/calendars/user/"]) *)val pcdata : string -> treepcdata s creates a text node. Equivalent to Pcdata s.