"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\xsd.exe"
/order /n:eDD.KlasyXML /c /language:CS
to generate my C# code.
Woks pretty fine but my xsd files contains type definition for example :
<!--==========================================================-->
<!--=== QuantityType ===-->
<!--==========================================================-->
<xs:simpleType name="QuantityType">
<xs:annotation>
<xs:documentation>
<doc:description value="Quantity" />
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:decimal">
<xs:totalDigits value="15" />
<xs:fractionDigits value="3" />
<xs:minExclusive value="0" />
<xs:pattern value="[1-9]\d{0,14}" />
<xs:pattern value="([1-9]\d{0,13}|0)\.[0-9]" />
<xs:pattern value="([1-9]\d{0,12}|0)\.\d[0-9]" />
<xs:pattern value="([1-9]\d{0,11}|0)\.\d\d[0-9]" />
</xs:restriction>
</xs:simpleType>
Element definition looks like this :
<xs:element name="Quantity" type="emcs:QuantityType"/>
But output in XML looks like this :
<q4:Quantity>2000.0000</q4:Quantity>
Is there any way to force xsd.exe to respect type definition and output xml in proper format like this :
<q4:Quantity>2000.000</q4:Quantity>
This is how I convert object to string :
public static string XMLToString<T>(this T toSerialize)
{
StreamReader streamReader = null;
MemoryStream memoryStream = null;
try
{
XmlSchemaSet schema = new XmlSchemaSet();
schema.Add("eDD.SchematyXML", "traderToEdd.xsd");
memoryStream = new MemoryStream();
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
XmlWriter xmlWriter = XmlWriter.Create(memoryStream, xmlWriterSettings);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
xmlSerializer.Serialize(xmlWriter, toSerialize);
memoryStream.Seek(0, SeekOrigin.Begin);
streamReader = new StreamReader(memoryStream);
return streamReader.ReadToEnd();
}
finally
{
if ((streamReader != null))
{
streamReader.Dispose();
}
if ((memoryStream != null))
{
memoryStream.Dispose();
}
}
}
How add schema or namespace to this ?
I probably do something wrong but it don't work for me. I tried but whatever I done fails. The solution was to use xsd2code. It can generate Fraction Digits Attribute and much more. Its not free but it is worth any penny.