use webdav_serde::Multistatus;
fn main() {
let xml = r#"<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:">
<D:response>
<D:href>/documents/</D:href>
<D:propstat>
<D:prop>
<D:displayname>Documents</D:displayname>
<D:getlastmodified>Mon, 13 Nov 2023 14:52:27 GMT</D:getlastmodified>
<D:resourcetype>
<D:collection />
</D:resourcetype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
<D:response>
<D:href>/documents/report.pdf</D:href>
<D:propstat>
<D:prop>
<D:displayname>report.pdf</D:displayname>
<D:getcontentlength>524288</D:getcontentlength>
<D:getcontenttype>application/pdf</D:getcontenttype>
<D:getlastmodified>Tue, 14 Nov 2023 10:30:00 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).expect("Failed to parse XML");
println!("WebDAV Response Summary");
println!("=======================\n");
for response in &multistatus.response {
println!("Resource: {}", response.href);
println!(" Name: {}", response.name());
println!(" Type: {}", if response.is_collection() { "Directory" } else { "File" });
let prop = &response.propstat.prop;
if let Some(display_name) = &prop.displayname {
println!(" Display Name: {}", display_name);
}
if let Some(size) = prop.getcontentlength {
println!(" Size: {} bytes ({:.2} KB)", size, size as f64 / 1024.0);
}
if let Some(content_type) = &prop.getcontenttype {
println!(" Content Type: {}", content_type);
}
if let Some(modified) = &prop.getlastmodified {
println!(" Last Modified: {}", modified);
}
println!();
}
println!("\nSerialized back to XML:");
println!("=======================");
match multistatus.to_xml() {
Ok(xml_output) => println!("{}", xml_output),
Err(e) => eprintln!("Failed to serialize: {}", e),
}
}