serde-xml-rs
serde-xml-rs copied to clipboard
Duplicate field $value error
I'm currently, as part of trying to learn how serde-xml-rs works, trying to parse Senate roll call data. When learning new XML libraries this is my go-to source as it usually is well formed and has some more advanced pieces. An example of a vote:
<vote>
<vote_number>00024</vote_number>
<vote_date>12-Jan</vote_date>
<issue>S.Con.Res. 3</issue>
<question>On the Motion <measure>S.Amdt. 180</measure></question>
<result>Rejected</result>
<vote_tally>
<yeas>51</yeas>
<nays>47</nays>
</vote_tally>
<title>Motion to Waive All Applicable Budgetary Discipline Re: Hatch Amdt. No. 180; To establish a deficit-neutral reserve fund relating to strengthening Social Security and repealing and replacing Obamacare, which has increased health care costs, raised taxes on middle-class families, reduced access to high quality care, created disincentives for work, and caused tens of thousands of Americans to lose coverage they had and liked, and replacing it with reforms that strengthen Medicaid and the Children's Health Insurance Program without prioritizing able-bodied adults over the disabled or children and lead to patient-centered step-by-step health reforms that provide access to quality, affordable private health care coverage for all Americans and their families by increasing competition, State flexibility, and individual choice, and safe-guarding consumer protections that Americans support.</title>
</vote>
When I try to deserialize the <question> tag I run into issues. I've been able to get it to (mostly) deserialize by setting up this structure:
// ...snip...
#[derive(Debug, Deserialize)]
struct Question {
#[serde(default)]
measure: String,
}
// ...snip...
#[derive(Debug, Deserialize)]
struct Vote {
vote_number: String,
vote_date: String,
issue: String,
question: Question,
result: String,
vote_tally: VoteTally,
title: String,
}
// ...snip...
However, with this data, the text that is included in the <question> tag is also important. I've tried changing the Question struct to the below example, but I get a panic with an error stating duplicate field $value.
#[derive(Debug, Deserialize)]
struct Question {
#[serde(rename="$value")]
text: String,
#[serde(default)]
measure: String,
}
The error, with backtrace:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: duplicate field `$value`', src/libcore/result.rs:906:4
stack backtrace:
0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
1: std::panicking::default_hook::{{closure}}
2: std::panicking::default_hook
3: std::panicking::rust_panic_with_hook
4: std::panicking::begin_panic
5: std::panicking::begin_panic_fmt
6: rust_begin_unwind
7: core::panicking::panic_fmt
8: core::result::unwrap_failed
9: <core::result::Result<T, E>>::unwrap
10: rust_parse_xml_serde::main
11: __rust_maybe_catch_panic
12: std::rt::lang_start
13: main
Is this expected? From what I've gathered so far, it seems I should be able to gather the text through $value, and so I'm not sure if I'm doing something verboten or if I've run into an actual bug.
I placed my whole code (with an example XML file) in a github repo.
This sounds like it's strongly tied to https://github.com/RReverser/serde-xml-rs/issues/55.