I'm trying to construct some classes such that I will get the desired result when serializing:
However this is my output based on the classes below. Notice that I want to suppress the parent <EmailAddressTo> element tag and only include the child <EmailAddressTo> nodes that have the values. Any suggestions on how to construct the EmailList class? Thanks.
classes:
Code:
<?xml version="1.0" encoding="utf-16"?>
<LDPDetails xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
<DistributionType>SMTP</DistributionType>
<DistributeTo>
<EmailList>
<EmailAddressTo>jean.stiles@reply.com</EmailAddressTo>
<EmailAddressTo>jeanstiles@comcast.net</EmailAddressTo>
<EmailAddressFrom>leads@chron.com</EmailAddressFrom>
</EmailList>
</DistributeTo>
</LDPDetails>
Code:
<?xml version="1.0" encoding="utf-16"?>
<LDPDetails xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
<DistributionType>SMTP</DistributionType>
<DistributeTo>
<EmailList>
<EmailAddressTo> --want to suppress
<EmailAddressTo>jean.stiles@reply.com</EmailAddressTo>
<EmailAddressTo>jeanstiles@comcast.net</EmailAddressTo>
</EmailAddressTo>--want to suppress
<EmailAddressFrom>leads@chron.com</EmailAddressFrom>
</EmailList>
</DistributeTo>
</LDPDetails>
classes:
Code:
public class LDPDetails
{
private String _distributionType;
private DistributeTo _distributeTo;
public String DistributionType
{
get {return this._distributionType;}
set {this._distributionType = value;}
}
public DistributeTo DistributeTo
{
get {return this._distributeTo;}
set {this._distributeTo = value;}
}
}
public class DistributeTo
{
private EmailList _emailList;
private String _soapAction;
private String _contentType;
private String _url;
public EmailList EmailList
{
get {return this._emailList;}
set {this._emailList = value;}
}
public String SoapAction
{
get {return this._soapAction;}
set {this._soapAction = value;}
}
public String ContentType
{
get {return this._contentType;}
set {this._contentType = value;}
}
public String URL
{
get {return this._url;}
set {this._url = value;}
}
}
public class EmailList
{
private String[] _emailAddressTo;
private String _emailAddressFrom;
[XmlArray(ElementName=null)]
[XmlArrayItem(Type = typeof(string), ElementName = "EmailAddressTo")]
public String[] EmailAddressTo
{
get
{
return this._emailAddressTo;
}
set
{
this._emailAddressTo = value;
}
}
public String EmailAddressFrom
{
get {return this._emailAddressFrom;}
set {this._emailAddressFrom = value;}
}
}