strong-xml icon indicating copy to clipboard operation
strong-xml copied to clipboard

feature request: implicit container tags

Open afflux opened this issue 4 years ago • 0 comments

I'm parsing AUTOSAR XML files that often wrap repeating elements in a container element. To parse this, I need many constructs like this:

#[derive(XmlRead, Debug, Clone)]
#[xml(tag = "COMPU-INTERNAL-TO-PHYS")]
struct CompuInternalToPhys<'a> {
    #[xml(child = "COMPU-SCALES", default)]
    compu_scales: CompuScales<'a>,
}

#[derive(XmlRead, Debug, Clone, Default)]
#[xml(tag = "COMPU-SCALES")]
struct CompuScales<'a>(#[xml(child = "COMPU-SCALE")] Vec<CompuScale<'a>>);

#[derive(XmlRead, Debug, Clone)]
#[xml(tag = "COMPU-SCALE")]
struct CompuScale<'a> { 
    [...]
}

I'd love to be able to specify the container type on the field of the outer structure like this:

#[derive(XmlRead, Debug, Clone)]
#[xml(tag = "COMPU-INTERNAL-TO-PHYS")]
struct CompuInternalToPhys<'a> {
    #[xml(container = "COMPU-SCALES", child = "COMPU-SCALE", default)]
    compu_scales: Vec<CompuScale<'a>>,
}

#[derive(XmlRead, Debug, Clone)]
#[xml(tag = "COMPU-SCALE")]
struct CompuScale<'a> { 
    [...]
}

If this is something you'd consider adding, I'd be happy to provide a PR.

afflux avatar Jun 22 '21 17:06 afflux