xml: Support CDATA

This commit is contained in:
Lennart
2025-02-05 17:56:52 +01:00
parent 0596fe6396
commit 89f2483dac
4 changed files with 45 additions and 3 deletions

View File

@@ -1,3 +1,5 @@
use std::string::FromUtf8Error;
use thiserror::Error;
#[derive(Debug, Error)]
@@ -6,6 +8,8 @@ pub enum XmlError {
QuickXmlError(#[from] quick_xml::Error),
#[error(transparent)]
QuickXmlAttrError(#[from] quick_xml::events::attributes::AttrError),
#[error(transparent)]
FromUtf8Error(#[from] FromUtf8Error),
#[error("Invalid tag [{0}]{1}. Expected [{2}]{3}")]
InvalidTag(String, String, String, String),
#[error("Missing field {0}")]

View File

@@ -81,6 +81,14 @@ impl<T: ValueDeserialize> XmlDeserialize for T {
}
string = String::from_utf8_lossy(text.as_ref()).to_string();
}
Event::CData(cdata) => {
let text = String::from_utf8(cdata.to_vec())?;
if !string.is_empty() {
// Content already written
return Err(XmlError::UnsupportedEvent("content already written"));
}
string = text;
}
Event::End(_) => break,
Event::Eof => return Err(XmlError::Eof),
_ => return Err(XmlError::UnsupportedEvent("todo")),