Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: (untagged)
Hi
I have a generated c# class for my xsd and I have generated my the xsd c# class using xsd.exe and I want to generate xml using this class.
this is what I have done:

this is part of my code that I wrote to generate the xml
when I run this it save an empty file
and also I don't know how to add the Vin value to it

string modelType = null;

LinqSqlDataContext db = new LinqSqlDataContext();
var reportData = from Vin in db.Vin_Ecus
                 from Global in db.Info_Globals
                              .Where(w =>
                                     w.NHard == Vin.NHard &&
                                     w.NVerHard == Vin.NVerHard &&
                                     w.NVerSoft == Vin.NVerSoft)
                              join Associate in db.InfoProg_wiTECH_Associas
                              on Global.NomeFile equals Associate.KeyJoined
                              where Vin.Vin == vinValue 
                  select new { modelType = Associate.Model_Type };


                  var data = new FlashListFlash { ECUtype = modelType };
                  //THIS IS MY Vin value probelm
                  //var data = new FlashList { Vin = vinValue}?????????????????????
                  var serializer = new XmlSerializer(typeof(FlashListFlash));
                  using (var stream = new StreamWriter("D:\\test.xml"))
                  serializer.Serialize(stream, data);


using System.Xml.Serialization;


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class FlashList {
    
    private FlashListFlash flashField;
    
    private string vinField;
    
    /// <remarks/>
    public FlashListFlash flash {
        get {
            return this.flashField;
        }
        set {
            this.flashField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string Vin {
        get {
            return this.vinField;
        }
        set {
            this.vinField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class FlashListFlash {
    
    private string eCUtypeField;
    
    private string valueField;
    
    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string ECUtype {
        get {
            return this.eCUtypeField;
        }
        set {
            this.eCUtypeField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlTextAttribute()]
    public string Value {
        get {
            return this.valueField;
        }
        set {
            this.valueField = value;
        }
    }
}



MY XSD file

XML
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="FlashList">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="flash">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute type="xs:string" name="ECUtype"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute type="xs:string" name="Vin"/>
    </xs:complexType>
  </xs:element>
</xs:schema>
Posted
Updated 24-Apr-15 4:37am
v3
Comments
Maciej Los 23-Apr-15 15:30pm    
Do not repost[^]!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900