webdav-serde 0.1.2

webdav-serde
Documentation
  • Coverage
  • 14.81%
    4 out of 27 items documented0 out of 10 items with examples
  • Size
  • Source code size: 34.32 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 694.44 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 23s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ahaoboy

webdav-serde

A Rust library for parsing and serializing WebDAV XML responses using quick-xml and serde.

Features

  • Parse WebDAV multistatus XML responses
  • Serialize Rust structs to WebDAV XML format
  • Support for all common WebDAV properties
  • Helper methods for working with WebDAV responses

Installation

Add this to your Cargo.toml:

[dependencies]
webdav-serde = "0.1.2"

Usage

Parsing WebDAV XML

use webdav_serde::Multistatus;

let xml = r#"<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:">
  <D:response>
    <D:href>/file.txt</D:href>
    <D:propstat>
      <D:prop>
        <D:getcontentlength>1024</D:getcontentlength>
        <D:getlastmodified>Mon, 13 Nov 2023 14:52:27 GMT</D:getlastmodified>
        <D:resourcetype></D:resourcetype>
      </D:prop>
      <D:status>HTTP/1.1 200 OK</D:status>
    </D:propstat>
  </D:response>
</D:multistatus>"#;

let multistatus = Multistatus::from_xml(xml).unwrap();

for response in &multistatus.response {
    println!("Path: {}", response.href);
    println!("Name: {}", response.name());
    println!("Is directory: {}", response.is_collection());
    
    if let Some(size) = response.propstat.prop.getcontentlength {
        println!("Size: {} bytes", size);
    }
}

Command Line Tool

Parse WebDAV XML files from the command line:

cargo run -- xml/list.xml

This will display:

  • Full parsed structure
  • Summary of collections and files
  • List of files with sizes

Supported Properties

  • displayname - Display name of the resource
  • creationdate - Creation date
  • getcontentlength - File size in bytes
  • getcontenttype - MIME type
  • getetag - Entity tag
  • getlastmodified - Last modification date
  • lockdiscovery - Lock information
  • resourcetype - Resource type (collection or file)
  • supportedlock - Supported lock types

Examples

See the xml/ directory for example WebDAV responses from different servers.

License

MIT

use serde_xml_rs::from_str;
use webdav_serde::Multistatus;


fn main() {
    let src = include_str!("../xml/list.xml");
    let item: Multistatus = from_str(src).unwrap();
    println!("{:#?}", item);
}