mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 14:08:23 +00:00
Migrate propfind and report to rustical_xml
This commit is contained in:
@@ -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),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user