Ignore attributes when looking for scalar values
This commit is contained in:
parent
8c2964b318
commit
8c618ada79
|
@ -31,12 +31,15 @@ impl<'cx, 'xml> Deserializer<'cx, 'xml> {
|
|||
}
|
||||
|
||||
pub fn take_str(&mut self) -> Result<Option<&'xml str>, Error> {
|
||||
match self.next() {
|
||||
Some(Ok(Node::AttributeValue(s))) => Ok(Some(s)),
|
||||
Some(Ok(Node::Text(s))) => Ok(Some(s)),
|
||||
Some(Ok(node)) => Err(Error::ExpectedScalar(format!("{node:?}"))),
|
||||
Some(Err(e)) => Err(e),
|
||||
None => Ok(None),
|
||||
loop {
|
||||
match self.next() {
|
||||
Some(Ok(Node::AttributeValue(s))) => return Ok(Some(s)),
|
||||
Some(Ok(Node::Text(s))) => return Ok(Some(s)),
|
||||
Some(Ok(Node::Attribute(_))) => continue,
|
||||
Some(Ok(node)) => return Err(Error::ExpectedScalar(format!("{node:?}"))),
|
||||
Some(Err(e)) => return Err(e),
|
||||
None => return Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,3 +74,21 @@ fn scalars() {
|
|||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Debug, FromXml, PartialEq)]
|
||||
struct ScalarElementAttr {
|
||||
s: String,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scalar_element_attr() {
|
||||
assert_eq!(
|
||||
from_str::<ScalarElementAttr>(
|
||||
"<ScalarElementAttr><s lang=\"en\">hello</s></ScalarElementAttr>"
|
||||
)
|
||||
.unwrap(),
|
||||
ScalarElementAttr {
|
||||
s: "hello".to_string(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue