Add basic support for CDATA
This commit is contained in:
parent
a6774baef4
commit
3372ccb981
|
@ -339,6 +339,9 @@ impl<'xml> Iterator for Context<'xml> {
|
|||
Ok(Token::Text { text }) => {
|
||||
return Some(decode(text.as_str()).map(Node::Text));
|
||||
}
|
||||
Ok(Token::Cdata { text, .. }) => {
|
||||
return Some(Ok(Node::Text(Cow::Borrowed(text.as_str()))));
|
||||
}
|
||||
Ok(Token::Declaration { .. }) => match self.stack.is_empty() {
|
||||
false => return Some(Err(Error::UnexpectedToken(format!("{token:?}")))),
|
||||
true => {}
|
||||
|
|
|
@ -55,3 +55,28 @@ fn special_entities() {
|
|||
"<StructSpecialEntities xmlns=\"URI\"><string>&"<>'aa</string><cow>&"<>'cc</cow></StructSpecialEntities>",
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, FromXml, ToXml)]
|
||||
struct SimpleCData<'a> {
|
||||
#[xml(borrow)]
|
||||
foo: Cow<'a, str>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_cdata() {
|
||||
assert_eq!(
|
||||
from_str::<SimpleCData>("<SimpleCData><foo><![CDATA[<fo&o>]]></foo></SimpleCData>")
|
||||
.unwrap(),
|
||||
SimpleCData {
|
||||
foo: Cow::Borrowed("<fo&o>")
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
to_string(&SimpleCData {
|
||||
foo: Cow::Borrowed("<foo>")
|
||||
})
|
||||
.unwrap(),
|
||||
"<SimpleCData><foo><foo></foo></SimpleCData>",
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue