Can serde deserialize XML with repeating keys?

I have an XML like this:

<root>
  <dict>
    <key>foo</key>
    <value>bar</value>
    <key>foo</key>
    <value>bar</value>
  </dict>
</root>

Am I assuming correctly that serde is not the right tool for this?

I solved it with xmltree:

let parsed = xmltree::Element::parse(data.as_slice())?;

let dict = parsed
    .get_child("dict")
    .ok_or(anyhow!("dict element not found"))?;

for (key_el, value_el) in dict.children.iter().filter_map(|n| n.as_element()).tuples() {
    if key_el.name != "key" || value_el.name != "value" {
        return Err(anyhow!("dict contained unexpected element"));
    }

    println!("{}: {}", key_el.get_text().unwrap(), value_el.get_text().unwrap());
}

Isn't this plist?

Ha, it is actually. I didn't know that was a standard and just assumed it was some proprietary structure of the application I'm using.

It is a proprietary structure, but it's somewhat widespread because of Apple. I've undeleted my post.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.