Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Building an xml from xsd in code will be tiresome. In the past I have used the <a href="http://msdn.microsoft.com/en-us/library/aa302296.aspx" rel="nofollow">XMLSampleGenerator</a> by Priya Lakshminarayanan. The sourcecode to this particular project is found <a href="http://www.microsoft.com/en-us/download/details.aspx?id=31609" rel="nofollow">here</a>. </p> <p>I needed to do pretty much what you wanted, but the sample generation of visual studio was not sufficient. The XmlSampleGenerator I provided a link to is similar to the VS sample generation, but obviously you have the source code, and as such you can debug and adjust it to your needs (in my case I needed proper sample regex expression generation). </p> <p>A word of warning: Generating xmls from a xsd is no easy task, so dont expect it to be. Good luck. </p> <p><strong>Edit:</strong> This code will generate an Xml that also contains a KilometerUpload Node. </p> <pre><code>namespace XmlGen { public class Program { private static void Main( string[] args ) { XmlSerializer serializer = new XmlSerializer(typeof(XmlItem)); TextWriter writer = new StreamWriter(@"C:\Users\hasch\Downloads\test.xml"); XmlItem item = new XmlItem(); serializer.Serialize(writer,item); } } public class XmlItem { public KilometerUpload KilometerUpload; public KilometerRegistration KilometerRegistration; public XmlItem() { KilometerUpload = new KilometerUpload(); KilometerRegistration = new KilometerRegistration(); } } public class KilometerUpload { } public class KilometerRegistration { public string ChassisNumber { get; set; } public string KilometerStatus { get; set; } public string TypeOfData { get; set; } public KilometerRegistration() { ChassisNumber = "WVWZZZ3CZ7E201402"; KilometerStatus = "78000"; TypeOfData = "120"; }}} </code></pre> <p>And this is the generated Xml: </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;XmlItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" &gt; &lt;KilometerUpload /&gt; &lt;KilometerRegistration&gt; &lt;ChassisNumber&gt;WVWZZZ3CZ7E201402&lt;/ChassisNumber&gt; &lt;KilometerStatus&gt;78000&lt;/KilometerStatus&gt; &lt;TypeOfData&gt;120&lt;/TypeOfData&gt; &lt;/KilometerRegistration&gt; </code></pre> <p></p> <p>Do keep in mind that this is in fact NOT generating xml from an xsd! If your xsd changes you will have to make major changes to your classes and such. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload