Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8842127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:53:15+00:00 2026-06-14T10:53:15+00:00

I want to serialize a class Ticket into xml. I get the error :XmlAttribute/XmlText

  • 0

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; }

Serialize Method

public string Serialize(object obj)
{
    var nsSerializer = new XmlSerializerNamespaces();
    nsSerializer.Add(String.Empty, String.Empty);

    var serializer = new XmlSerializer(typeof(Ticket), String.Empty);

    using (StringWriter writer = new StringWriter())
    {
        ExtendedXmlTextWriter xmlTextWriter = new ExtendedXmlTextWriter(writer);
        serializer.Serialize(xmlTextWriter, obj, nsSerializer);

        //return writer.ToString();

        XElement root = new XElement("custom_fields", new XAttribute("type", "array"),
            new XElement("custom_field",
                new XAttribute("name", "Standby Reason"),
                new XAttribute("id", 6)
                ), new XElement("value"),
                    new XElement("custom_field",
                        new XAttribute("name", "Close Date"),
                        new XAttribute("id", 84)
                        )
                        );

        return (writer.ToString() + root.ToString());
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:53:16+00:00Added an answer on June 14, 2026 at 10:53 am

    Sometimes Linq To Xml can be very helpful

    XElement root = new XElement("ticket",
                            new XElement("custom_fields",
                                new XAttribute("type", "array"),
                                new XElement("custom_field",
                                    new XAttribute("name", "Standby Reason"),
                                    new XAttribute("id", 6)
                                ),
                                new XElement("value"),
                                new XElement("custom_field",
                                    new XAttribute("name", "Close Date"),
                                    new XAttribute("id", 84)
                                )
                            )
                    );
    
    string xml = root.ToString();
    

    OUTPUT:

    <ticket>
      <custom_fields type="array">
        <custom_field name="Standby Reason" id="6" />
        <value />
        <custom_field name="Close Date" id="84" />
      </custom_fields>
    </ticket>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Joo.java class and I want to serialize it into XML using
I want to serialize a class to xml and store that in a field
I want to Serialize a 60mb file into XML but it gives me System
I want to serialize an object into an xml and I want the filename
I have a class that I want to serialize [System.Xml.Serialization.XmlTypeAttribute(Namespace = http://xyz.com/schema)] public class
I want to serialize the Arraylist of type ArrayList<Class> and the class contains two
I have a class that I want to serialize to xml. The class looks
I want to serialize an xml string into collection of objects, but I can
I have a class which I want to serialize to xml. I want to
I have the following class that I want to serialize to an XML file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.