EDN Admin
Well-known member
How do I deserialize XML to 2 different classes based on an attribute? To make it simple, I have the classes below.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public Class One { <span style="color:Blue; public <span style="color:Blue; string Value1 {<span style="color:Blue; get;<span style="color:Blue; set;} <span style="color:Blue; public <span style="color:Blue; string Value2 {<span style="color:Blue; get;<span style="color:Blue; set;} }
[/code]
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public Class Two
{
<span style="color:Blue; public <span style="color:Blue; int Value1 {<span style="color:Blue; get;<span style="color:Blue; set;}
<span style="color:Blue; public <span style="color:Blue; int Value2 {<span style="color:Blue; get;<span style="color:Blue; set;}
}
[/code]
When I serialize them ( which I have figured out already ), they will serialize like below.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; Item <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; One<span style="color:Black; "<span style="color:Blue; > <span style="color:Blue; <<span style="color:#A31515; Value1<span style="color:Blue; >Some value<span style="color:Blue; </<span style="color:#A31515; Value1<span style="color:Blue; > <span style="color:Blue; <<span style="color:#A31515; Value2<span style="color:Blue; >Another value<span style="color:Blue; </<span style="color:#A31515; Value2<span style="color:Blue; > </Item <span style="color:Blue; <<span style="color:#A31515; Item <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Two<span style="color:Black; "<span style="color:Blue; > <span style="color:Blue; <<span style="color:#A31515; Value1<span style="color:Blue; >1234<span style="color:Blue; </<span style="color:#A31515; Value1<span style="color:Blue; > <span style="color:Blue; <<span style="color:#A31515; Value2<span style="color:Blue; >5678<span style="color:Blue; </<span style="color:#A31515; Value2<span style="color:Blue; > </Item
[/code]
I need to know how to deserialize based on the name attribute. Yes, I could make it simple and serialize with the element names of One and Two, but my problem trying to solve has many elements with the same name, but is determined by attributes like
name, type, and extends.
Anyone know of a solution? Thanks in advance.
View the full article
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public Class One { <span style="color:Blue; public <span style="color:Blue; string Value1 {<span style="color:Blue; get;<span style="color:Blue; set;} <span style="color:Blue; public <span style="color:Blue; string Value2 {<span style="color:Blue; get;<span style="color:Blue; set;} }
[/code]
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public Class Two
{
<span style="color:Blue; public <span style="color:Blue; int Value1 {<span style="color:Blue; get;<span style="color:Blue; set;}
<span style="color:Blue; public <span style="color:Blue; int Value2 {<span style="color:Blue; get;<span style="color:Blue; set;}
}
[/code]
When I serialize them ( which I have figured out already ), they will serialize like below.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; Item <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; One<span style="color:Black; "<span style="color:Blue; > <span style="color:Blue; <<span style="color:#A31515; Value1<span style="color:Blue; >Some value<span style="color:Blue; </<span style="color:#A31515; Value1<span style="color:Blue; > <span style="color:Blue; <<span style="color:#A31515; Value2<span style="color:Blue; >Another value<span style="color:Blue; </<span style="color:#A31515; Value2<span style="color:Blue; > </Item <span style="color:Blue; <<span style="color:#A31515; Item <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Two<span style="color:Black; "<span style="color:Blue; > <span style="color:Blue; <<span style="color:#A31515; Value1<span style="color:Blue; >1234<span style="color:Blue; </<span style="color:#A31515; Value1<span style="color:Blue; > <span style="color:Blue; <<span style="color:#A31515; Value2<span style="color:Blue; >5678<span style="color:Blue; </<span style="color:#A31515; Value2<span style="color:Blue; > </Item
[/code]
I need to know how to deserialize based on the name attribute. Yes, I could make it simple and serialize with the element names of One and Two, but my problem trying to solve has many elements with the same name, but is determined by attributes like
name, type, and extends.
Anyone know of a solution? Thanks in advance.
View the full article