Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a class from xsd file in net core

I need to generate a class from an xsd in net core. In dotnet standard I used commandline xsd filename.xsd /c. But how to I create this class in net core. Anyone knows how to do this?

When I add a class generated with xsd.exe I get several errors.

Example

    Error   CS0234  The type or namespace name 'SerializableAttributeAttribute' does not exist in the namespace 'System' (are you missing an assembly reference?)


Error   CS0234  The type or namespace name 'DesignerCategoryAttribute' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) 

Error   CS0234  The type or namespace name 'XmlTypeAttributeAttribute' does not exist in the namespace 'System.Xml.Serialization' (are you missing an assembly reference?)

Error   CS0246  The type or namespace name 'AnonymousType' could not be found (are you missing a using directive or an assembly reference?) 

Attributes from a class in autogen file

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
like image 417
joakimja Avatar asked May 04 '17 08:05

joakimja


People also ask

Can we generate XML from XSD?

To create an XML file from an XSD file: Right-click the XML Documents folder in your data development project, and select New > XML. The New XML File wizard opens.

Can we generate wsdl from XSD?

To create the wsdl out of xsd, we need to have an xsd having the parameters with types defined to it. So lets create an xsd called helloWorld which accepts name and gender as request and returns greetings as response. To create an xsd, Create a project (dynamic web project or simple java project).


2 Answers

I have now solved this issue with adding nugets to my project.

  • System.Xml.XmlSerializer

Solution: Removes the serializations attribute issues except the DesignerCategoryAttribute

  • Newtonsoft.json

Solution: Removes the DesignerCategoryAttribute

Now it is possible to compile the xsd.exe generated class and use it in net core

like image 114
joakimja Avatar answered Oct 15 '22 13:10

joakimja


netstandard2.0 can compile xsd.exe generated files with no problems

like image 2
fiorebat Avatar answered Oct 15 '22 14:10

fiorebat