diff --git a/instant-xml/src/de.rs b/instant-xml/src/de.rs index 6e4a8d6..fb489ce 100644 --- a/instant-xml/src/de.rs +++ b/instant-xml/src/de.rs @@ -31,12 +31,15 @@ impl<'cx, 'xml> Deserializer<'cx, 'xml> { } pub fn take_str(&mut self) -> Result, 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), + } } } diff --git a/instant-xml/tests/scalar.rs b/instant-xml/tests/scalar.rs index 9b806a9..3720d2f 100644 --- a/instant-xml/tests/scalar.rs +++ b/instant-xml/tests/scalar.rs @@ -74,3 +74,21 @@ fn scalars() { }) ); } + +#[derive(Debug, FromXml, PartialEq)] +struct ScalarElementAttr { + s: String, +} + +#[test] +fn scalar_element_attr() { + assert_eq!( + from_str::( + "hello" + ) + .unwrap(), + ScalarElementAttr { + s: "hello".to_string(), + } + ); +}