pub struct Multistatus {
pub response: Vec<Response>,
}Fields§
§response: Vec<Response>Implementations§
Source§impl Multistatus
impl Multistatus
Sourcepub fn from_xml(xml: &str) -> Result<Self, DeError>
pub fn from_xml(xml: &str) -> Result<Self, DeError>
Parse WebDAV multistatus XML from a string
Examples found in repository?
examples/parse.rs (line 35)
3fn main() {
4 let xml = r#"<?xml version="1.0" encoding="utf-8"?>
5<D:multistatus xmlns:D="DAV:">
6 <D:response>
7 <D:href>/documents/</D:href>
8 <D:propstat>
9 <D:prop>
10 <D:displayname>Documents</D:displayname>
11 <D:getlastmodified>Mon, 13 Nov 2023 14:52:27 GMT</D:getlastmodified>
12 <D:resourcetype>
13 <D:collection />
14 </D:resourcetype>
15 </D:prop>
16 <D:status>HTTP/1.1 200 OK</D:status>
17 </D:propstat>
18 </D:response>
19 <D:response>
20 <D:href>/documents/report.pdf</D:href>
21 <D:propstat>
22 <D:prop>
23 <D:displayname>report.pdf</D:displayname>
24 <D:getcontentlength>524288</D:getcontentlength>
25 <D:getcontenttype>application/pdf</D:getcontenttype>
26 <D:getlastmodified>Tue, 14 Nov 2023 10:30:00 GMT</D:getlastmodified>
27 <D:resourcetype></D:resourcetype>
28 </D:prop>
29 <D:status>HTTP/1.1 200 OK</D:status>
30 </D:propstat>
31 </D:response>
32</D:multistatus>"#;
33
34 // Parse the XML
35 let multistatus = Multistatus::from_xml(xml).expect("Failed to parse XML");
36
37 println!("WebDAV Response Summary");
38 println!("=======================\n");
39
40 for response in &multistatus.response {
41 println!("Resource: {}", response.href);
42 println!(" Name: {}", response.name());
43 println!(" Type: {}", if response.is_collection() { "Directory" } else { "File" });
44
45 let prop = &response.propstat.prop;
46
47 if let Some(display_name) = &prop.displayname {
48 println!(" Display Name: {}", display_name);
49 }
50
51 if let Some(size) = prop.getcontentlength {
52 println!(" Size: {} bytes ({:.2} KB)", size, size as f64 / 1024.0);
53 }
54
55 if let Some(content_type) = &prop.getcontenttype {
56 println!(" Content Type: {}", content_type);
57 }
58
59 if let Some(modified) = &prop.getlastmodified {
60 println!(" Last Modified: {}", modified);
61 }
62
63 println!();
64 }
65
66 // Demonstrate serialization
67 println!("\nSerialized back to XML:");
68 println!("=======================");
69 match multistatus.to_xml() {
70 Ok(xml_output) => println!("{}", xml_output),
71 Err(e) => eprintln!("Failed to serialize: {}", e),
72 }
73}Sourcepub fn to_xml(&self) -> Result<String, SeError>
pub fn to_xml(&self) -> Result<String, SeError>
Serialize to XML string
Examples found in repository?
examples/parse.rs (line 69)
3fn main() {
4 let xml = r#"<?xml version="1.0" encoding="utf-8"?>
5<D:multistatus xmlns:D="DAV:">
6 <D:response>
7 <D:href>/documents/</D:href>
8 <D:propstat>
9 <D:prop>
10 <D:displayname>Documents</D:displayname>
11 <D:getlastmodified>Mon, 13 Nov 2023 14:52:27 GMT</D:getlastmodified>
12 <D:resourcetype>
13 <D:collection />
14 </D:resourcetype>
15 </D:prop>
16 <D:status>HTTP/1.1 200 OK</D:status>
17 </D:propstat>
18 </D:response>
19 <D:response>
20 <D:href>/documents/report.pdf</D:href>
21 <D:propstat>
22 <D:prop>
23 <D:displayname>report.pdf</D:displayname>
24 <D:getcontentlength>524288</D:getcontentlength>
25 <D:getcontenttype>application/pdf</D:getcontenttype>
26 <D:getlastmodified>Tue, 14 Nov 2023 10:30:00 GMT</D:getlastmodified>
27 <D:resourcetype></D:resourcetype>
28 </D:prop>
29 <D:status>HTTP/1.1 200 OK</D:status>
30 </D:propstat>
31 </D:response>
32</D:multistatus>"#;
33
34 // Parse the XML
35 let multistatus = Multistatus::from_xml(xml).expect("Failed to parse XML");
36
37 println!("WebDAV Response Summary");
38 println!("=======================\n");
39
40 for response in &multistatus.response {
41 println!("Resource: {}", response.href);
42 println!(" Name: {}", response.name());
43 println!(" Type: {}", if response.is_collection() { "Directory" } else { "File" });
44
45 let prop = &response.propstat.prop;
46
47 if let Some(display_name) = &prop.displayname {
48 println!(" Display Name: {}", display_name);
49 }
50
51 if let Some(size) = prop.getcontentlength {
52 println!(" Size: {} bytes ({:.2} KB)", size, size as f64 / 1024.0);
53 }
54
55 if let Some(content_type) = &prop.getcontenttype {
56 println!(" Content Type: {}", content_type);
57 }
58
59 if let Some(modified) = &prop.getlastmodified {
60 println!(" Last Modified: {}", modified);
61 }
62
63 println!();
64 }
65
66 // Demonstrate serialization
67 println!("\nSerialized back to XML:");
68 println!("=======================");
69 match multistatus.to_xml() {
70 Ok(xml_output) => println!("{}", xml_output),
71 Err(e) => eprintln!("Failed to serialize: {}", e),
72 }
73}Trait Implementations§
Source§impl Debug for Multistatus
impl Debug for Multistatus
Source§impl<'de> Deserialize<'de> for Multistatus
impl<'de> Deserialize<'de> for Multistatus
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for Multistatus
impl PartialEq for Multistatus
Source§impl Serialize for Multistatus
impl Serialize for Multistatus
impl StructuralPartialEq for Multistatus
Auto Trait Implementations§
impl Freeze for Multistatus
impl RefUnwindSafe for Multistatus
impl Send for Multistatus
impl Sync for Multistatus
impl Unpin for Multistatus
impl UnsafeUnpin for Multistatus
impl UnwindSafe for Multistatus
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more