Migrate propfind and report to rustical_xml

This commit is contained in:
Lennart
2024-12-23 16:44:26 +01:00
parent 8e0a25b223
commit 72844aa94e
28 changed files with 528 additions and 335 deletions

View File

@@ -74,34 +74,39 @@ impl<T: XmlRootTag + XmlDeserialize> XmlDocument for T {
Self: XmlDeserialize,
{
let mut buf = Vec::new();
let event = reader.read_event_into(&mut buf)?;
let empty = matches!(event, Event::Empty(_));
match event {
Event::Start(start) | Event::Empty(start) => {
let (ns, name) = reader.resolve_element(start.name());
let matches = match (Self::root_ns(), &ns, name) {
// Wrong tag
(_, _, name) if name.as_ref() != Self::root_tag() => false,
// Wrong namespace
(Some(root_ns), ns, _) if &ResolveResult::Bound(Namespace(root_ns)) != ns => {
false
}
_ => true,
};
if !matches {
let root_ns = Self::root_ns();
return Err(XmlDeError::InvalidTag(
format!("{ns:?}"),
String::from_utf8_lossy(name.as_ref()).to_string(),
format!("{root_ns:?}"),
String::from_utf8_lossy(Self::root_tag()).to_string(),
));
};
loop {
let event = reader.read_event_into(&mut buf)?;
let empty = matches!(event, Event::Empty(_));
match event {
Event::Decl(_) => { /* <?xml ... ?> ignore this */ }
Event::Comment(_) => { /* ignore this */ }
Event::Start(start) | Event::Empty(start) => {
let (ns, name) = reader.resolve_element(start.name());
let matches = match (Self::root_ns(), &ns, name) {
// Wrong tag
(_, _, name) if name.as_ref() != Self::root_tag() => false,
// Wrong namespace
(Some(root_ns), ns, _)
if &ResolveResult::Bound(Namespace(root_ns)) != ns =>
{
false
}
_ => true,
};
if !matches {
let root_ns = Self::root_ns();
return Err(XmlDeError::InvalidTag(
format!("{ns:?}"),
String::from_utf8_lossy(name.as_ref()).to_string(),
format!("{root_ns:?}"),
String::from_utf8_lossy(Self::root_tag()).to_string(),
));
};
return Self::deserialize(&mut reader, &start, empty);
}
_ => {}
};
Err(XmlDeError::UnknownError)
return Self::deserialize(&mut reader, &start, empty);
}
_ => return Err(XmlDeError::UnknownError),
};
}
}
}