Skip to content

Skip intermediate nodes #365

@pronebird

Description

@pronebird

Hi,

I have XML that has container/wrapper types around collections of nodes and I'd like to skip them when parsing, for example:

<Response>
  <Entities count="2">
      <Entity />
      <Entity />
  </Entities>
</Response>

i.e it works when I provide a struct Entities as a container that holds children:

#[derive(Deserialize, Debug)]
pub struct Response {
    #[serde(rename = "Entities")]
    entities: Entities,
}

#[derive(Deserialize, Debug)]
struct Entities {
    count: u32,

    #[serde(rename = "Entity")]
    children: Vec<Entity>,
}

#[derive(Deserialize, Debug)]
struct Entity {
   ///...
}

But what I would really like to do is to eliminate the struct Entities and have a Vec<Entity> instead, i.e:

#[derive(Deserialize, Debug)]
pub struct Response {
    #[serde(rename = "Entities")]
    entities: Vec<Entity>,
}

How would one achieve that?

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionserdeIssues related to mapping from Rust types to XML

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions