XmlAttribute/XmlText cannot be used to encode complex type

Posted by Conrad C on Stack Overflow See other posts from Stack Overflow or by Conrad C
Published on 2012-11-16T16:35:58Z Indexed on 2012/11/16 16:59 UTC
Read the original article Hit count: 283

Filed under:
|
|
|
|

I want to serialize a class Ticket into xml. I get the error :"XmlAttribute/XmlText cannot be used to encode complex type" because of my customfield class.

This is how the xml for customfields should look like ( the attribute array is nesseray but I don't understand how to create it):

<custom_fields type="array">
<custom_field name="Standby Reason" id="6">
<value/>
</custom_field>
<custom_field name="Close Date" id="84">

Class Ticket

public class Ticket
{
    [XmlElement("custom_fields")]
    public CustomFields Custom_fields { get; set; }

Class CustomFields

[Serializable]
public class CustomFields
{
    [XmlAttribute("array")]
    public List<CustomField> custom_field { get; set; }

Class CustomField

[Serializable]
public class CustomField
{
    [XmlIgnore]
    public string Name { get; set; }

    [XmlElement]
    public int Id { get; set; }

    [XmlElement]
    public string Value { get; set; }

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET