C# - Maintenance of Classes generated from xsd file

Asked

Viewed 296 times

7

I’m developing an application that uses classes generated from xsd files made available by the IRS with the xsd.exe. I use them to serialize xml files from the objects of these classes after performing validation of what was filled with xsd itself.

So far so good, the problem is that these xsd files change version when the IRS understands well, which will cause me a lot of headache to update the xsd and the class generated from it for all customers.

It would force me to re-generate the C# class from the new version xsd and recompile the application. Which is very bad. Not to mention that if I eat ball and some customer is left without the updated build, no xml generated by the application will be valid.

OK enough crying, as I am very amateur, I would like to ask: There is a way to keep xsd files and their respective classes up to date without so much manual work?

  • You can add two different versions of the xsd file to your question to get a better context of the problem?

  • @Brunocosta I believe that the colleague is no longer following the community, but it seems to me a question still pertinent. The XSD referred to are from the documentation of the electronic invoice, which can be found here: http://www.nfe.fazenda.gov.br/portal/listaConteudo.aspx?tipConteudo=/fwLvLUSmU8= (several versions including)

  • The problem is that if the XSD changes radically, it’s because things have been changed by who did the scheming, the government, unfortunately. When the change is incremental, minus the code to be changed.

1 answer

1

The generated class C# is the representation of the Schema used, in the case described from the XSD file (XML Schema Definition), so it is logical that if the original schema changes, the class should change accordingly. Ideally, do not edit this class generated by XSD.exe. When there are changes, you must generate new classes using the XSD.exe tool, adapt the program code, compile and distribute the new version.

In fact:

1) The problem is that if XSD changes radically, it is because things have been changed by the schemer, the government, unfortunately the code also has to be changed.
When the change is incremental, minus the code to be changed.

I think it is currently not possible to have a fully automatic solution to update the application code/logic + database data as the government XSD schematics change.

So for now what you can do is when there are changes in the / XSD layouts, run XSD.exe again creating the new updated classes, and tailor the code and logic that uses these classes.

2) To keep the application updated on the client you can use the Clickonce with WPF, the .appinstaller or MSIX (preview) with UWP.

These technologies can be configured to check if there is new version of the Application and then download and update in the client. ClickOnce

  • See also https://answall.com/q/217909/5704

Browser other questions tagged

You are not signed in. Login or sign up in order to post.