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

  • Home
  • SEARCH
  • 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 1032411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:04:22+00:00 2026-05-16T14:04:22+00:00

I have a set of classes build using xsd.exe, and I am trying to

  • 0

I have a set of classes build using xsd.exe, and I am trying to serialise them. However, an attribute is not being included in the resulting XML. Here is part of the schema where the problem lies.

<xsd:element name="Widget">
    <xsd:complexType>
        /* sequence removed for brevity */
        <xsd:attribute name="Version" type="Version" use="optional" default="1.1"/>
    </xsd:complexType>
</xsd:element>
<xsd:simpleType name="Version">
    <xsd:restriction base="xsd:string">
        <xsd:enumeration value="1.0"/>
        <xsd:enumeration value="1.1"/>
    </xsd:restriction>
</xsd:simpleType>

xsd.exe generated a property called “Version” on a “Widget” class and another property called “VersionSpecified”, but this not appear to generate the attribute when I serialize even when set to true:

[XmlAttributeAttribute]
[DefaultValueAttribute(Version.Version_1_1)]
public Version Version { get; set; }

[Serialization.XmlIgnoreAttribute]
public bool VersionSpecified { get; set; }

And this is the enumeration on which it is based:

/// <remarks/>
[GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[Serializable]
public enum Version
{
    [XmlEnumAttribute("1.0")]
    Version_1_0,

    [XmlEnumAttribute("1.1")]
    Version_1_1,
}

Code snippet as per request

Widget widget = new Widget();
widget.Version = Version.Version_1_1;
widget.VersionSpecified = true;    

XmlSerializer serializer = new XmlSerializer(widget.GetType());
serializer.Serialize(/*Memory Stream object*/, widget);

Does anyone have any thoughts on why the serialization refuses to introduce the attribute?

  • 1 1 Answer
  • 3 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-05-16T14:04:23+00:00Added an answer on May 16, 2026 at 2:04 pm

    Its because you specified the default value as “1.1”. The serialiser will not create the element/attribute when the property is equal to its default value.

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

Sidebar

Related Questions

I'm using ASP.NET MVC RC2. I have a set of classes that were auto-generated
I am using Hibernate to do mapping. One of my classes have a set
I am trying to build a set of domain classes for a legacy database
I'm not sure if I'm using classes correctly. I'm attempting to build a simple
I am trying to build a program using model-view-controller. Specifically: I have a state
I'm trying to build an app using Jersey, Rest, Tomcat, c3p0 etc. I have
I have an MVC3 razor project, which I am trying to build using multiple
I have a set of xsd files and I need to generate java classes
Present Scenario : I have a set of classes that all take a common
I have a requirement where in i have a set of classes and they

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.