Thread: XML Serialization and Required Fields

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445

    XML Serialization and Required Fields

    let's say I have a class called foo:
    Code:
    public class foo
    {
        public string name { get; set; }
        public string description { get; set; }
    }
    xsd.exe will generate a schema like so:
    Code:
      <xs:element name="foo" nillable="true" type="foo" />
      <xs:complexType name="foo">
        <xs:sequence>
          <xs:element minOccurs="0" maxOccurs="1" name="name" type="xs:string" />
          <xs:element minOccurs="0" maxOccurs="1" name="description" type="xs:string" />
        </xs:sequence>
      </xs:complexType>
    the trouble is those attributes that say
    Code:
    minOccurs="0"
    meaning that they are optional.

    what attribute can I add to my properties to make them requred?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    I found my own answer.

    apparently, if it's a property that contains a nullable type, it's implicitly optional. changing my class to the following:
    Code:
    public class foo
    {
        public string name;
        public string description;
    }
    made the fields required.

    Edit: actually that didn't work either, so I'm still in need of some advice.
    Last edited by Elkvis; 09-30-2011 at 09:09 AM. Reason: my answer was wrong

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I have no idea. But this might be what you want: Serialization in C# .NET II - XML Serialization - CodeProject


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    I saw that page, but it doesn't really address my question. thanks for trying anyway. I looked at just about every link in the first 3 pages of google for multiple queries.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Serialization
    By SevenThunders in forum C++ Programming
    Replies: 4
    Last Post: 04-29-2008, 03:12 AM
  2. Replies: 3
    Last Post: 06-12-2007, 11:21 AM
  3. Serialization yay!
    By Shamino in forum C++ Programming
    Replies: 11
    Last Post: 06-10-2007, 05:53 PM
  4. Serialization
    By Asagohan in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2005, 10:57 PM
  5. Serialization
    By bigdan43 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2005, 10:41 AM