views:

33

answers:

0

Hi all,

I have the following XSD which is generated to a class.

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" id="sales" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;

  <xs:element name="sales">
    <xs:complexType>
      <xs:sequence minOccurs="0" maxOccurs="unbounded">

      <xs:element name="sale">                       
        <xs:complexType>          
          <xs:sequence>
            <xs:element name="type" type="xs:string"/>
            <xs:element name="title" type="xs:string"/>
            <xs:element name="description" type="xs:string"/>
            <xs:element name="starttime" type="xs:string"/>
            <xs:element name="endtime" type="xs:string"/>
            <xs:element name="image" type="xs:string"/>
            <xs:element name="url" type="xs:string"/>
            <xs:element name="shippingcosts" type="xs:string"/>
            <xs:element name="men" type="xs:string"/>
            <xs:element name="women" type="xs:string"/>
            <xs:element name="children" type="xs:string"/>
            <xs:element name="discount" type="xs:string"/>
            <xs:element name="stock" type="xs:string"/>
          </xs:sequence>
          <xs:attribute name="id" type="xs:int" use="required"/>
        </xs:complexType>        
      </xs:element>

      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>

Now when i fill this list of sales with some data and do a XmlSerializer.Serialize my results are:

  <sale id="40">
    <type>sale</type>
    <title>Test Sale</title>
    <description>Test Sale</description>
    <starttime>31-10-2010 15:00:00</starttime>
    <endtime>4-11-2010 1:00:00</endtime>
    <url>http://www.example.nl/&lt;/url&gt;
    <shippingcosts>6.95</shippingcosts>
    <men>1</men>
    <women>1</women>
    <children>1</children>
    <discount>50</discount>
    <stock>1</stock>
  </sale>

What I need is that every value inside each element is encapsulated with the CDATA tag. For example:

<![CDATA[sale]]>

The code of my generated class is:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4927")]
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
    public partial class sales
    {

        private List<salesSale> saleField;

        public sales()
        {
            this.saleField = new List<salesSale>();
        }

        [System.Xml.Serialization.XmlElementAttribute("sale", Order = 0)]
        public List<salesSale> sale
        {
            get
            {
                return this.saleField;
            }
            set
            {
                this.saleField = value;
            }
        }
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4927")]
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
    public partial class salesSale
    {

        private string typeField;

        private string titleField;

        private string descriptionField;

        private string starttimeField;

        private string endtimeField;

        private string imageField;

        private string urlField;

        private string shippingcostsField;

        private string menField;

        private string womenField;

        private string childrenField;

        private string discountField;

        private string stockField;

        private int idField;

        [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
        public string type
        {
            get
            {
                return this.typeField;
            }
            set
            {
                this.typeField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
        public string title
        {
            get
            {
                return this.titleField;
            }
            set
            {
                this.titleField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 2)]
        public string description
        {
            get
            {
                return this.descriptionField;
            }
            set
            {
                this.descriptionField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 3)]
        public string starttime
        {
            get
            {
                return this.starttimeField;
            }
            set
            {
                this.starttimeField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 4)]
        public string endtime
        {
            get
            {
                return this.endtimeField;
            }
            set
            {
                this.endtimeField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 5)]
        public string image
        {
            get
            {
                return this.imageField;
            }
            set
            {
                this.imageField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 6)]
        public string url
        {
            get
            {
                return this.urlField;
            }
            set
            {
                this.urlField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 7)]
        public string shippingcosts
        {
            get
            {
                return this.shippingcostsField;
            }
            set
            {
                this.shippingcostsField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 8)]
        public string men
        {
            get
            {
                return this.menField;
            }
            set
            {
                this.menField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 9)]
        public string women
        {
            get
            {
                return this.womenField;
            }
            set
            {
                this.womenField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 10)]
        public string children
        {
            get
            {
                return this.childrenField;
            }
            set
            {
                this.childrenField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 11)]
        public string discount
        {
            get
            {
                return this.discountField;
            }
            set
            {
                this.discountField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute(Order = 12)]
        public string stock
        {
            get
            {
                return this.stockField;
            }
            set
            {
                this.stockField = value;
            }
        }

        [System.Xml.Serialization.XmlAttributeAttribute()]
        public int id
        {
            get
            {
                return this.idField;
            }
            set
            {
                this.idField = value;
            }
        }
    }

Thanks in advance.

Gr

Martijn