c# create xml file from xsd class code example
Example 1: c# generate xml from xsd at runtime
public XmlDocument GenerateEmptyPdfTemplate(GenerateEmptyPdfTemplateDto generateEmptyPdfTemplateDto)
{
XmlDocument doc = new XmlDocument();
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(null, XmlReader.Create(new StringReader(generateEmptyPdfTemplateDto.XsdDocument)));
schemaSet.Compile();
XmlSampleGenerator generator = new XmlSampleGenerator(schemaSet, new XmlQualifiedName("foo"));
generator.MaxThreshold=1;
doc = new XmlDocument();
using (XmlWriter writer = doc.CreateNavigator().AppendChild())
{
generator.WriteXml(writer);
}
return doc;
}
Example 2: how to create xml file in c#
new XDocument(
new XElement("root",
new XElement("someNode", "someValue")
)
)
.Save("foo.xml");