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 };
var serializer = new XmlSerializer(typeof(FlashListFlash));
using (var stream = new StreamWriter("D:\\test.xml"))
serializer.Serialize(stream, data);
using System.Xml.Serialization;
[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;
public FlashListFlash flash {
get {
return this.flashField;
}
set {
this.flashField = value;
}
}
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Vin {
get {
return this.vinField;
}
set {
this.vinField = value;
}
}
}
[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;
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ECUtype {
get {
return this.eCUtypeField;
}
set {
this.eCUtypeField = value;
}
}
[System.Xml.Serialization.XmlTextAttribute()]
public string Value {
get {
return this.valueField;
}
set {
this.valueField = value;
}
}
}
MY XSD file
<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>