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

Jesus Ernesto Castelo estrada 11 Reputation points
2021-01-30T16:38:12.55+00:00

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

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,245 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Timon Yang-MSFT 9,571 Reputation points
    2021-02-01T02:19:55.607+00:00

    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.

    0 comments No comments

  2. safepage 1 Reputation point
    2021-04-12T13:00:28.837+00:00

    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.

    0 comments No comments