quick-xml
quick-xml copied to clipboard
Deserializing an element's content containing <EM> styling tags in the text
I'm trying to the following xml:
<TESTCASES PROFILE="IBM XML Conformance Test Suite - Production 1">
<TEST URI="valid/P01/ibm01v01.xml" TYPE="valid" ID="ibm-valid-P01-ibm01v01.xml" ENTITIES="none" SECTIONS="2.1" OUTPUT="valid/P01/out/ibm01v01.xml">
Tests with a xml document consisting of <EM>prolog</EM> followed by
<EM>element</EM> then <EM>Misc</EM>
</TEST>
</TESTCASES>
I want it so that all text between <TEST></TEST> deserializes into a struct field (ideally a String).
#[derive(Debug, Deserialize)]
#[serde(rename = "TESTCASES")]
struct TestCasesTier2 {
#[serde(rename = "@PROFILE")]
profile: String,
#[serde(rename = "@xml:base")]
base: Option<String>,
#[serde(rename = "TEST")]
tests: Vec<TestCase>,
}
#[derive(Debug, Deserialize)]
#[serde(rename = "TEST")]
struct TestCase {
#[serde(rename = "@URI")]
uri: String,
#[serde(rename = "@ID")]
id: String,
#[serde(rename = "@ENTITIES")]
entities: Option<String>,
#[serde(rename = "@SECTIONS")]
sections: String,
#[serde(rename = "@TYPE")]
expected_outcome: TestCaseType,
#[serde(rename = "@OUTPUT")]
output: Option<String>,
#[serde(rename = "$text")]
test_comment: String,
}
#[derive(PartialEq, Debug, Deserialize)]
#[serde(rename_all = "kebab-case")]
enum TestCaseType {
Valid,
Invalid,
NotWf,
Error,
}
I've tried String and Vector<String> for the test_comment field, but I still get a Error: Custom("duplicate field $text"). Is there something I'm missing here? Or will I need to add an EM struct in order to get this to deserialize?
Duplicate of #257.
Unfortunately, this case is not yet solved.