I know there are several answers on this board regarding .xsd scheme creation, but I found nothing that really fits what I'm trying to do.
I have a very simple XML file with nested elements etc. (but no namespaces or dtd) and I'm trying to generate a XSD file out of it. I reflected the code from Microsoft XSD.exe (which is being brought up very often when it comes to XSD generation) and saw a scheme generation is done by using XmlSchemaInference class (InferScheme() method).
Now, my XML file is already loaded using XDocument.Load() from the LINQ-namespace. But when I look at XmlSchemaInference, I see that this only takes an XmlTextReader as an xml document argument.
Do I get this right that I have to load my XML file for using with LINQ as an XDocument and then load it again with XmlTextReader to create a XSD? Or does XDocument provides similiar methods as it contains the extension method .Validate()?
I'm very confused when it comes to XML, as .net seems to provide hundreds of classes, but no one of them is able to provide full functionality. :/
What I'm trying to do in short:
- Load XML file using
XDocument(LINQ) - Create XSD scheme using native framework /
XmlSchemeSetmethods (noxsd.exestuff) from XDocument - with new XDocument object, save using
XDocument.Save()
What it seems I have to do:
- Load XML file using
XDocument - Load XML file again using
XmlTextReader - Pass
XmlTextReadertoXmlSchemaInference - Pass new
XmlTextWritertoXmlSchemaInference - Save document using
XmlTextWriter
... pretty ridiculous, mh?