Programmatically create XML file from XSD

I have an XSD file and I want to create an XML file at runtime based on XSD. (My question is basically the same as this , with the exception of the .NET world, and not for Java.)

I launched xsd.exe /c /l:vb MyTest.xsd, but generates a class that cannot be created and used, because it has nested classes that are never created. It looks like the generated class is only used for XML deserialization, but I don't have an XML file for deserialization.

A run xsd.exe /d /l:vb MyTest.xsdcreates a dataset, but it seems that using this code would be more complicated than just XmlDocumentmanual recording .

What is the best way to create an XML file based on a specific schema?

+2
source share
3 answers

Turns out I'm just dumb. While the classes generated by xsd contain uninitialized nested classes, they are displayed through public properties, so nothing prevents me from creating an instance myself.

Something like the following:

ElementA.ElementB = New ElementB()
ElementA.ElementB.Name = "Jason"
+1
source

Read this article: http://msdn.microsoft.com/en-us/library/aa302296.aspx includes an installer and samples when using the XmlSampleGenerator API.

+1
source

XML (oXygen), . , , .

+1

Source: https://habr.com/ru/post/1730722/


All Articles