How can I generate a xsd file from a XML file using vb.net code?
Asked
Active
Viewed 268 times
0
-
1You can generate an XSD file from an XML file programmatically, and get an XSD that the XML conforms to, but it's not likely to be very useful. For example, it may well constrain all postcodes to have the pattern AA99 9AA, just because all the postcodes in your sample XML conform to that pattern. In practice to get a useful schema, you need human intervention. – Michael Kay Feb 21 '20 at 21:44
1 Answers
1
I found this answer and converted it to vb.net
Using reader = XmlReader.Create("filename.xml")
Dim schemaInference = New XmlSchemaInference()
Dim schemaSet = schemaInference.InferSchema(reader)
For Each s As XmlSchema In schemaSet.Schemas()
Using writer = XmlWriter.Create("schema.xsd")
s.Write(writer)
End Using
Next
End Using
Sometimes it helps to learn about this thing called a search engine. You may have heard of a search engine. If so, you can try to search one too!
Try this
generate xsd from xml vb.net site stackoverflow.com
and if that doesn't work, you can always look for c# answers because they are more abundant
generate xsd from xml c# site stackoverflow.com
The answer I found was in the first result of the search engine.

djv
- 15,168
- 7
- 48
- 72