xsd to xml

Given an xsd file, is it possible to generate an xml file?

Who is Participating?
eternal_21Connect With a Mentor Commented:
Do you have a Strongly Typed dataset in your application?  You can produce the XML string with this:

  public static string WriteDataSet(System.Data.DataSet dataSet)
    System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
    dataSet.WriteXml(memoryStream, System.Data.XmlWriteMode.WriteSchema);
    memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
    return new System.IO.StreamReader(memoryStream).ReadToEnd();

Personally, I use the System.Data.XmlWriteMode.IgnoreSchema option.
An XSD file is in XML format.... what exactly are you trying to do?
doudou74Author Commented:
I have a schema .xsd,
and i need to get a .xml file that corresponds to this xsd.

a .xsd defines just the structure.
the xml file contains data values.

You can do it using some tools using XmlSpy.

If you want to do it programatically there is a tool called XML Schema Definition Tool (Xsd.exe)
You can get information about this tool from MSDN.

There is a particular option called XSd sample.xsd /d  which
Generates a class derived from DataSet that corresponds to the specified schema.
Then from this dataset
To read XML data into the derived class, use the System.Data.DataSet.ReadXml method.
All Courses

From novice to tech pro — start learning today.