RReverser / serde-xml-rs

xml-rs based deserializer for Serde (compatible with 1.0+)
https://crates.io/crates/serde-xml-rs
MIT License
269 stars 90 forks source link

Error: custom: duplicate field `whatever` #169

Closed 1sra3l closed 2 years ago

1sra3l commented 2 years ago

@punkstarman I have issues with this still. Joe's Window Manager use xml for configuring it. Here is the issue: (added spacer and button comments below)

<!--snip -->
    <Tray x="0" y="-1" autohide="off" delay="1000">
<!-- first button -->
        <TrayButton label="JWM">root:1</TrayButton>
<!-- first  spacer -->
        <Spacer width="2"/>0
<!-- second button -->
        <TrayButton label="_">showdesktop</TrayButton>
<!-- second spacer -->
        <Spacer width="2"/>

        <Pager labeled="true"/>

        <TaskList maxwidth="256"/>

        <Swallow width="32" height="32" name="xclock">xclock</Swallow>

        <Dock/>
        <Clock format="%l:%M %p"><Button mask="123">exec:xclock</Button></Clock>

    </Tray>
<!--snip -->

Here is code using your suggestion:

pub fn read<P: Clone + AsRef<std::path::Path> + std::fmt::Debug>(filename:P) -> Option<Self> {
        if let Ok(file_string) = std::fs::read_to_string(filename.clone()) {
            let mut de = serde_xml_rs::Deserializer::new_from_reader(file_string.as_bytes())
                .non_contiguous_seq_elements(true);
            let decoded:Jwm = match Jwm::deserialize(&mut de) {
                Ok(decoded) => decoded,
                Err(e) => {
                    println!("Error:{}", e);
                    return None
                }, 
            };
            return Some(decoded);
        }
        None
    }

Yet I get: Error:custom: duplicate field 'Spacer' What am I missing from your suggestions?

Originally posted by @1sra3l in https://github.com/RReverser/serde-xml-rs/issues/165#issuecomment-1025184934

1sra3l commented 2 years ago

@RReverser Do you intend to address this vital component of XML, or are you content with simply ignoring that your library is unusable and broken for a large subset of XML?

If you need a well known example, not fringe like the widely used freedesktop Menu files, look at SVG. There is no way you can support the vector graphic file if you do not allow people to put multiple out of order elements, it is art and that is how art works.

Do you want me to close this bug since you "don't care/won't fix", or do you intend to make this work at some point? I do understand you already closed a similar bug because this issue was "fixed", but it is not fixed, even if I add the hacky custom deserialization workaround, and add the non-working .non_contiguous_seq_elements(true) it still continues to gloriously fail consistently.

If I am missing some minor key thing, please correct my ignorance, I simply want your library to work for XML using serde (like the name of the library suggests), which it still does not.

RReverser commented 2 years ago

are you content with simply ignoring that your library is unusable and broken for a large subset of XML?

Yes.

P.S. Perhaps you should check your tone - this is OSS project and nobody owes you any fixes or features.

1sra3l commented 2 years ago

@RReverser Sorry, I was frustrated, I am sorry for being direct and honest about my frustration. It is unfortunate that you are settling for a broken library, since this is OSS I thought it meant you were passionate about your code's quality.

You might consider renaming your library the name is a bit misleading.

RReverser commented 2 years ago

Well, I'm not. I created a library to solve the use-case I had and shared code with others in case it helps them too. That's open-source.

It doesn't mean I actively maintain the library or develop new features - in fact, it was another volunteer who did most of maintenance in the recent years.

If you want to also volunteer and send PRs, you're welcome to do so. If you want to switch to alternative that better addresses your use-case, that's also fine. But just expressing frustration because it doesn't cover certain use-cases, that are important to you, is not a helpful course of action.

1sra3l commented 2 years ago

@RReverser Thanks for being understanding! I am not nearly as talented at programming as you or your contributors, so you would likely have more work than if I made no contribution. Thank you for your work, and again I apologize for being frustrated and expressing it to you in the way I did. I appreciate your level of reserve even though I was frustrated.