I’m trying to extract a list of items from an xml document using serde
and serde-xml-rs
. The xml has the form seen here. I would like to extract the <IdList>
from that search result. Because it’s relatively simple, I’ve been successful turning the result into strings and matching a regex to get the information, but I’d like to figure out how to do this with serde
. The examples I have found all point out how to extract field attributes rather than data: <Id num="12345">
vs <Id>12345</Id>
. What I have tried is:
#[derive(Serialize, Deserialize, Debug)]
struct IdList {
#[serde(rename="$value")]
IdList: Vec<Id>
}
#[derive(Serialize, Deserialize, Debug)]
struct Id {
#[serde(rename="$value")]
id: String
}
This gives the error
thread ‘main’ panicked at ‘called
Result::unwrap()
on anErr
value: Expected token XmlEvent::Characters(s), found StartElement(Id, {"": “”, “xml”: “http : / / w w w . w 3 .org/XML/1998/namespace”, “xmlns”: “http : / / w w w .w3.org/2000/xmlns/”})’
How should I be handling this?