locked
Create XML file from existing DTD file RRS feed

  • Question

  • User-1564729832 posted

    I have a DTD file with some rules. Now i have to create an xml file based on this schema in VS 2012

    Tuesday, April 30, 2013 1:41 AM

Answers

  • User166892907 posted
     using (var stream = new MemoryStream(File.ReadAllBytes("schema.xsd")))
                {
                    var schema = XmlSchema.Read(XmlReader.Create(stream ), null);
                    var gen = new XmlSampleGenerator(schema, new XmlQualifiedName("rootElement"));
                    gen.WriteXml(XmlWriter.Create(@"c:\temp\autogen.xml"));
                    Console.WriteLine("Autogenerated file is here : c:\temp\autogen.xml");
                }  

    http://msdn.microsoft.com/en-us/library/aa302296.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 30, 2013 8:20 AM

All replies

  • User166892907 posted

    I don't think this is possible in VS 2012.

    but you can try this http://www.oxygenxml.com/

    or you can convert your dtd into xsd with this http://www.hitsw.com/xml_utilites/

    and then generate xml sample from xsd http://msdn.microsoft.com/en-us/library/dd489258.aspx

    Tuesday, April 30, 2013 5:27 AM
  • User-1564729832 posted

    i want to generate xml from schema through code. Please can anyone help me on this?

    Tuesday, April 30, 2013 8:17 AM
  • User166892907 posted
     using (var stream = new MemoryStream(File.ReadAllBytes("schema.xsd")))
                {
                    var schema = XmlSchema.Read(XmlReader.Create(stream ), null);
                    var gen = new XmlSampleGenerator(schema, new XmlQualifiedName("rootElement"));
                    gen.WriteXml(XmlWriter.Create(@"c:\temp\autogen.xml"));
                    Console.WriteLine("Autogenerated file is here : c:\temp\autogen.xml");
                }  

    http://msdn.microsoft.com/en-us/library/aa302296.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 30, 2013 8:20 AM
  • User-1564729832 posted

    Thanks for the link u have given. But i have a problem here. It works well for simple schemas.

    I have some complex schema which uses Xlink and ref attributes. Error occurs while generating the xml. Can u please provide some better solution for this?

    Monday, May 6, 2013 12:24 AM