Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create XSD from XML in Code

Tags:

c#

xml

xsd

I am using this piece of code from MSDN to create an XSD from an XML

XmlReader reader = XmlReader.Create("contosoBooks.xml");
XmlSchemaSet schemaSet = new XmlSchemaSet();
XmlSchemaInference schema = new XmlSchemaInference();

schemaSet = schema.InferSchema(reader);

foreach (XmlSchema s in schemaSet.Schemas())
{
   textbox.text = s.ToString();
}

I want to output the .xsd based on my xml file. When I generate the .xsd file, the only content I get inside it is: System.Xml.Schema.XmlSchema

When I generate the XSD using Visual Studio option to create Schema, it comes out properly. However, I have over 150 xml docs that I need to create XSD for hence need a programmatic option. Can anyone help?

like image 855
SharePointDummy Avatar asked Apr 03 '14 11:04

SharePointDummy


People also ask

How do I create an XSD from an XML file?

With the desired XML document opened in the active editor tab, choose Tools | XML Actions | Generate XSD Schema from XML File on the main menu. The Generate Schema From Instance Document dialog box opens. and select the desired file in the dialog that opens.

Can we convert XML to XSD?

Free tool to generate XSD (XML schema) from the XML file. There is option to browse the input . xml file and to save the output .

Can I generate XSD from WSDL?

xsd using following steps : Create library (optional) > Right Click , New Message Model File > Select SOAP XML > Choose Option 'I already have WSDL for my data' > 'Select file outside workspace' > 'Select the WSDL bindings to Import' (if there are multiple) > Finish. This will give you the . xsd and .

Can we convert XML to XSD online?

Use this XML to XML Schema converter tool by pasting or uploading XML in the left box below. Results will appear in the box on the right. Generate XML Schema from XML with this XSD Generator. Input (XML) - Paste your XML here.


1 Answers

I use this command line:

Administrator:Developer Command Prompt for VS2013

Create xsd file from xml:

xsd FullFilePath.xml /outputdir:myOutputDir

Generate object to represent that xsd file in our project.

xsd /c /n:myNameSpace FullPath\fileName.xsd

then it will tell where the .cs file is created.

like image 136
L. Ben Avatar answered Oct 20 '22 04:10

L. Ben