N
Nikolay Anestev
Hi all. I have the following xml content:
<?xml version="1.0"?>
<_ARRAY LangCode="2">
<LABELS Count="4">
<code>Code</code>
<ident>Ident</ident>
</LABELS>
<USERS_ACCOUNTS>
<code>14403</code>
<ident>1714 358113156 01 1</ident>
</USERS_ACCOUNTS>
<USERS_ACCOUNTS>
<code>14403</code>
<ident>1714 358113156 09 7</ident>
</USERS_ACCOUNTS>
</_ARRAY>
, that must be serialized into the following types:
[XmlRoot("USERS_ACCOUNTS")] public class Account
{
private int code;
private string ident;
[XmlElement("code")] public int Code
{
get{ return code; }
set{ code = value; }
}
[XmlElement("ident")] public string Ident
{
get{ return ident; }
set{ ident = value; }
}
}
[XmlRoot("_ARRAY"), XmlInclude(typeof(Account))] public class Accounts
{
[XmlAnyElement]
public XmlElement[] AllElements;
[XmlArrayItem("USERS_ACCOUNTS")]
public Account[] List;
}
, where the serialization code looks like this:
XmlSerializer serializer = new XmlSerializer( typeof( Accounts ) );
Accounts accs = (Accounts)serializer.Deserialize( new StringReader( Xml ) );
The result is that all the three nodes in the xml are serialized as unknown
types as items of the AllElements array, while I want to serialize the two
USERS_ACCOUNTS as array items of the List array.
What am I doing wrong? This drove me crazy already. Thank you in advance.
Nikolay Anestev
<?xml version="1.0"?>
<_ARRAY LangCode="2">
<LABELS Count="4">
<code>Code</code>
<ident>Ident</ident>
</LABELS>
<USERS_ACCOUNTS>
<code>14403</code>
<ident>1714 358113156 01 1</ident>
</USERS_ACCOUNTS>
<USERS_ACCOUNTS>
<code>14403</code>
<ident>1714 358113156 09 7</ident>
</USERS_ACCOUNTS>
</_ARRAY>
, that must be serialized into the following types:
[XmlRoot("USERS_ACCOUNTS")] public class Account
{
private int code;
private string ident;
[XmlElement("code")] public int Code
{
get{ return code; }
set{ code = value; }
}
[XmlElement("ident")] public string Ident
{
get{ return ident; }
set{ ident = value; }
}
}
[XmlRoot("_ARRAY"), XmlInclude(typeof(Account))] public class Accounts
{
[XmlAnyElement]
public XmlElement[] AllElements;
[XmlArrayItem("USERS_ACCOUNTS")]
public Account[] List;
}
, where the serialization code looks like this:
XmlSerializer serializer = new XmlSerializer( typeof( Accounts ) );
Accounts accs = (Accounts)serializer.Deserialize( new StringReader( Xml ) );
The result is that all the three nodes in the xml are serialized as unknown
types as items of the AllElements array, while I want to serialize the two
USERS_ACCOUNTS as array items of the List array.
What am I doing wrong? This drove me crazy already. Thank you in advance.
Nikolay Anestev