Add skipping of unrecognized elements (fixes #12)
This commit is contained in:
@@ -88,6 +88,16 @@ impl<'de, R: Read> Deserializer<R> {
|
||||
Ok(next_event)
|
||||
}
|
||||
|
||||
pub fn skip_element(&mut self, mut cb: impl FnMut(&XmlEvent)) -> Result<(), String> {
|
||||
let depth = self.depth;
|
||||
|
||||
while self.depth >= depth {
|
||||
cb(&self.next_event()?);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_map_value(&mut self) {
|
||||
self.is_map_value = true;
|
||||
}
|
||||
|
||||
@@ -780,3 +780,45 @@ fn de_flatten() {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn de_subitem_issue_12() {
|
||||
#[derive(Default, PartialEq, Debug, YaDeserialize)]
|
||||
pub struct Struct {
|
||||
id: i32,
|
||||
}
|
||||
|
||||
convert_and_validate!(
|
||||
r#"
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Struct>
|
||||
<id>54</id>
|
||||
<SubStruct>
|
||||
<id>86</id>
|
||||
</SubStruct>
|
||||
</Struct>
|
||||
"#,
|
||||
Struct,
|
||||
Struct { id: 54 }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn de_subitem_issue_12_attributes() {
|
||||
#[derive(Default, PartialEq, Debug, YaDeserialize)]
|
||||
pub struct Struct {
|
||||
#[yaserde(attribute)]
|
||||
id: i32,
|
||||
}
|
||||
|
||||
convert_and_validate!(
|
||||
r#"
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Struct id="54">
|
||||
<SubStruct id="86" />
|
||||
</Struct>
|
||||
"#,
|
||||
Struct,
|
||||
Struct { id: 54 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user