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 8063991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:13:44+00:00 2026-06-05T11:13:44+00:00

I am trying to create xml like this: <CreditApplication> <ApplicantData> <FirstName> John </FirstName> <LastName>

  • 0

I am trying to create xml like this:

<CreditApplication>
    <ApplicantData>
        <FirstName> John </FirstName>
        <LastName> Smith </LastName>
    </ApplicantData>
    <CoApplicantData>
        <FirstName> Mary </FirstName>
        <LastName> Jane </LastName>
    </CoApplicantData>
</CreditApplication>

And I’ve defined my classes as such:

[XmlRoot("CreditApplication")]
public class CreditApplication
{
    [XmlElement("ApplicantData")]
    public CreditApplicant Applicant;
    [XmlElement("CoApplicantData")]
    public CreditApplicant CoApplicant;
}

public class CreditApplicant : INotifyPropertyChanged
{
    ...
    [XmlElement("FirstName")]
    public string FirstName { set; get; }
    [XmlElement("LastName")]
    public string LastName { set; get; }
    ...
}

And further down in the CreditApplication class I have references to enumerations that are defined elsewhere in my program that also need to be made serilizable.

When I actually run the program and try to serlizize the class with:

XmlSerializer applicantXMLSerializer = new XmlSerializer(typeof(CreditApplication));
StringWriter applicantStringWriter = new StringWriter();
XmlWriter applicantXmlWriter = XmlWriter.Create(applicantStringWriter);
applicantXMLSerializer.Serialize(applicantXmlWriter, application);
var applicantXML = applicantStringWriter.ToString();

But I get the error: There was an error reflecting type 'Models.Credit.CreditApplication'

Does anyone have any idea what I’m doing wrong?

EDIT:

I’ve updated the above code to reflect the changes suggested. There are other issues that have presented themselves though.

I have an enum defined as such:

[DataContract]
public enum Relationship
{
    Spouse = 4,
    ResidesWith = 1,
    Parent = 2,
    Other = 3,
    PersonalGuarantor = 5,
    CoApplicant = 6
}

As seen above, zero is not a defined option. Because of this, there is no default value. I have designed the program around the idea that a relationship that is not set defaults to zero. That way I can easily see if a value has been set. If I have zero defined and then have it initialize to “No Relationship” or something like that, then there is no way to tell if the user set the value to “No Relationship”, or if they simply did not choose an option.

Moved:

XML Serialization of Enums Without Default Values

  • 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-05T11:13:46+00:00Added an answer on June 5, 2026 at 11:13 am

    You want to use the XMLElement Attribute instead of the XMLAttribute Attribute if your fields are supposed to be separate elements in the XML.

    For example:

    <SimpleXML name="test">
      <child>SomeValue</child>
    </SimpleXML>
    

    name is an attribute, whereas child is an element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an xml entry that looks like this using python and
Im trying to create a xml the should look like this <?xml version=1.0 encoding=iso-8859-1?>
Given an XML layout like this, I'm trying to create a XSD schema to
I am trying to create a sort of generic xml parser, like this: Part
I'm trying to create some XML like this: <parameter name=srid type=java.lang.Integer>24729</parameter> notice that the
I'm trying to create XML Schema using lxml. For the begining something like this:
I am trying to create an XML file to conform to someones XSD this
I'm trying to create a C# application that extracts data from pages like this
Hi I'm trying to create a row like this: The row should be with
I would like to create an XML file like this: <?xml version=1.0 encoding=UTF-8?> <text>

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.