-
Notifications
You must be signed in to change notification settings - Fork 238
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
Deserializing tag with attribute values into Map #383
Comments
Generally, this is the same problem as #241 -- you have a <>
<name>Name</name>
<desc>Description</desc>
</> Conceptually, there is no such a defined mapping from XML to Rust in quick-xml for that. You may think, that It is certain that we require two kinds of
The current |
I think I have a related issue, but want to confirm. Say I have the following structure: <upper>
<inner name = "a">1</inner>
<inner name = "b">2</inner>
<inner name = "c">3</inner>
</upper> Ideally, I'd like to deserialize into the following: {upper: {inner: {"a" : 1, "b" : 2, "c" : 3}}} Do I have to write a custom deserializer impl for this? |
Yes, probably this is somehow related. Your JSON example can be modelled by the following Rust code: struct Upper {
inner: Inner,
}
struct Inner {
a: usize,
b: usize,
c: usize,
} In XML this struct will be represented as <any-tag>
<inner a="1" b="2" c="3"/>
</any-tag> or <any-tag>
<inner>
<a>1</a>
<b>1</b>
<c>1</c>
</inner>
</any-tag> I think, that your original XML should be modelled as struct Upper {
inner: Vec<Inner>,
}
#[serde(tag = "name", content = "$value")]
enum Inner {
a(usize),
b(usize),
c(usize),
} (where So if you want to get the Rust representation closer to your JSON representation, you in any case need the custom (de)serializer. |
Assume we have below xml structure:
when
<attr>
tag doesn't have attribute values, quick-xml parses successfully into Map (HashMap, MultiMap)Container ( "attr" : { Name(Name), Desc(Description) } )
but when
<attr>
havename
value I need some wrapper struct withrename = "$value"
. In that case it works only withattr: Vec<AttrDefChoice>
.Is there any way to achieve parsing of tags with values into Map?
The text was updated successfully, but these errors were encountered: