Skip to content

Commit

Permalink
refactor: some xml function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukáš Chudíček committed Nov 12, 2023
1 parent bb4d88c commit edb796f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/xml_parsing/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,20 @@ where
pub fn find_start_of<XR: XmlReader<BR>, BR: BufRead>(
xml: &mut XR,
expected_name: &str,
) -> Result<(), String> {
) -> Result<(), XmlReadingError> {
loop {
match xml.next() {
Ok(xml::reader::XmlEvent::StartElement { name: n, .. })
match xml.next()? {
xml::reader::XmlEvent::StartElement { name: n, .. }
if n.local_name == expected_name =>
{
return Ok(());
return Ok(())
}
xml::reader::XmlEvent::EndDocument => {
return Err(XmlReadingError::UnexpectedEvent {
expected: ExpectedXmlEvent::Start(expected_name.into()),
got: XmlEvent::EndDocument,
})
}
Ok(xml::reader::XmlEvent::EndElement { .. }) => continue,
Ok(xml::reader::XmlEvent::EndDocument) => return Err("end of document".to_string()),
Err(e) => return Err(format!("error: {:?}", e)),
_ => continue, // should be uninteresting
}
}
Expand Down

0 comments on commit edb796f

Please sign in to comment.