#How do I flatten this xml object

10 messages · Page 1 of 1 (latest)

onyx axle
#

So I am trying to flatten this xml object that is built into many rust objects:

<RootNode scale="4" font_size="32" color="#f7e5e4" xmlns="https://www.loc.gov/marc/marcxml.html">
    <Background type="Fixed3x3RepeatableBackground" asset="dark_blue_background.png" position="center" size="x:800,y:500" frame_id="0">
        <Button type="ImageButton" asset="x_button.png" position="t:20,r:20" frame_id="0" hover_frame_id="1" click_frame_id="2" event_id="1" scale="3" />
        <Grid pagination_size="x:3,y:6" grid_layout="x:3,y:6" size="x:600,y:375" scale="2" font_size="24">
            <Grid pagination_size="x:2,y:1" grid_layout="x:2,y:1" size="x:200,y:63">
                <Button
                    type="BooleanImageButton"
                    asset="check_box_button.png"
                    position="r:5"
                    truth_frame_id="0"
                    truth_hover_frame_id="1"
                    truth_click_frame_id="2"
                    false_frame_id="3"
                    false_hover_frame_id="4"
                    false_click_frame_id="5"
                    event_id="2"
                    sync_id="1"
                    />
                <Text position="l:5">
                    Show FPS
                </Text>
            </Grid>
        </Grid>
    </Background>
</RootNode>

Every single one of these objects are represented in my Elements Enum:

pub enum Element {
    MissingTexture(missing_texture::MissingTexture),
    Button(Box<dyn button::traits::ButtonElement>),
    TilingSprite(Box<dyn tiling_sprites::traits::TilingSpriteElement>),
    Background(Box<dyn background::traits::BackgroundElement>),
    Grid(grid::Grid),
    Text(text::Text),
    RootNode(root_node::RootNode),
    Empty(()),
}

Stuff like the Background, Grid, and RootNode have children elements. I want to write an iterator that can traverse through every element in my dom mutably. I looked into the chain function under std::iter and it looks I

#

can't dynamically add different iterators to the chain function

sage geyser
#

this sort of stuff doesn't actually work well with iterators

onyx axle
#

ah

sage geyser
#

consider using a visitor

onyx axle
#

I'll do that then

#

thanks

sage geyser
#

if you do want to try an iterator

onyx axle
#

As long as I can traverse the entire xml document mutably and adapt specific elements, i'm fine