question

JesusErnestoCasteloestrada-6711 avatar image
2 Votes"
JesusErnestoCasteloestrada-6711 asked safepage-9882 answered

there is a way to generate C# class from XSD 1.1?

there is a way to generate C# class from XSD 1.1?



i can't transform the XSD 1.1 to 1.0, there is a tool for generate the clases direct from an XSD 1.1?



i know there is XSD.exe but not recognises "assert" from XSD 1.1

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered

If XSD.exe does not apply to the current file, then I am afraid you need to manually convert it to a class.

The xsd file is a special xml file. There are many ways to read it in C#, such as:

         static void Main(string[] args)
         {
             XmlTextReader reader = new XmlTextReader(@"C:\Users\timony\Desktop\1.xsd");
             XmlSchema myschema = XmlSchema.Read(reader, ValidationCallback);
         }
    
         static void ValidationCallback(object sender, ValidationEventArgs args)
         {
             if (args.Severity == XmlSeverityType.Warning)
                 Console.Write("WARNING: ");
             else if (args.Severity == XmlSeverityType.Error)
                 Console.Write("ERROR: ");
    
             Console.WriteLine(args.Message);
         }

Or

             var xsd = XDocument.Load(@"C:\Users\timony\Desktop\1.xsd");
             var ns = xsd.Root.GetDefaultNamespace();
             var prefix = xsd.Root.GetNamespaceOfPrefix("xsd");
             var vehicle = xsd.Root.Element(prefix + "complexType");
             var sections = vehicle.Element(prefix + "sequence")
                                 .Elements(prefix + "element").ToList();

Then assign the value of each element to the properties of the class you created.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

safepage-9882 avatar image
0 Votes"
safepage-9882 answered

No you would need to strip out the XSD 1.1 specific parts.

You could try Liquid XML Objects which is a direct replacement for xsd.exe and support XSD 1.1.

It is commercial product but small XSD can be used under the free community edition license.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.