Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with mixed sequence with attributes? #700

Open
cigrainger opened this issue Jan 10, 2024 · 1 comment
Open

Help with mixed sequence with attributes? #700

cigrainger opened this issue Jan 10, 2024 · 1 comment
Labels
serde Issues related to mapping from Rust types to XML

Comments

@cigrainger
Copy link

cigrainger commented Jan 10, 2024

Hi there! Thank you for the excellent library.

I'm quite stuck and I was hoping someone might be able to help me. I'm trying to switch to quick-xml from serde-xml-rs and I've got everything switched except this last bit. I've got some XML that looks like this (excuse the escaped quotes):

<ifi-parties>
	<ifi-standardized-name country=\"CH\" type=\"U.S. Company or Corporation\" number=\"070058\">
		<addressbook>
			<name>Company Name</name>
		</addressbook>
	</ifi-standardized-name>
	<ifi-standardized-name-current country=\"CH\" number=\"070058\">
		<addressbook>
			<name>Company Name</name>
		</addressbook>
	</ifi-standardized-name-current>
</ifi-parties>

There's more deserialisation code, but the relevant bits are:

#[derive(Debug, Deserialize, PartialEq, NifMap)]
struct IfiParties {
    ifi_standardized_name: Option<Vec<IfiStandardizedName>>,
    ifi_standardized_name_current: Option<Vec<IfiStandardizedNameCurrent>>,
    ifi_standardized_name_probable: Option<Vec<IfiStandardizedNameProbable>>,
}

#[derive(Debug, Deserialize, PartialEq, NifMap)]
struct IfiStandardizedName {
    #[serde(rename = "@country")]
    country: Option<String>,
    #[serde(rename = "@type")]
    r#type: Option<String>,
    #[serde(rename = "@number")]
    number: Option<u64>,
    addressbook: Addressbook,
}

#[derive(Debug, Deserialize, PartialEq, NifMap)]
struct IfiStandardizedNameCurrent {
    #[serde(rename = "@country")]
    country: Option<String>,
    #[serde(rename = "@type")]
    r#type: Option<String>,
    #[serde(rename = "@number")]
    number: Option<u64>,
    addressbook: Addressbook,
}

#[derive(Debug, Deserialize, PartialEq, NifMap)]
struct IfiStandardizedNameProbable {
    #[serde(rename = "@country")]
    country: Option<String>,
    #[serde(rename = "@type")]
    r#type: Option<String>,
    #[serde(rename = "@number")]
    addressbook: Addressbook,
}

#[derive(Debug, Deserialize, PartialEq, NifMap)]
struct Addressbook {
    #[serde(rename = "$value", default)]
    name: String,
}

No matter what I do, I'm getting None for ifi_standardized_name, ifi_standardized_name_current, and ifi_standardized_name_probable. I've got overlapped-lists enabled. If I rename them to kebab-case, I get a deserialization error. I'm at a loss here and am not really sure how to figure it out, so I was hoping someone might be able to point out something obvious I'm doing wrong here.

Thank you in advance!

@Mingun Mingun added the serde Issues related to mapping from Rust types to XML label Jan 10, 2024
@leftmostcat
Copy link

What's the error you get when using kebab-case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

3 participants