XSD.EXE Generate classes in C# - EFD Reinf v1_04_00

Asked

Viewed 807 times

1

I am trying to generate XSD.exe classes in C# from the Reinf XSD files:

EFD Reinf v1_04_00
http://sped.rfb.gov.br/arquivo/show/2802

As follows:

C:\Reinf\XSD>xsd evtInfoContribuinte-v1_04_00.xsd /classes

XSD.exe returns error:

Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.6.1055.0]
Copyright (C) Microsoft Corporation. All rights reserved.
Schema validation warning: The 'http://www.w3.org/2000/09/xmldsig#:Signature' el
ement is not declared. Line 754, position 10.

Warning: Schema could not be validated. Class generation may fail or may produce
 incorrect results.

Error: Error generating classes for schema 'evtInfoContribuinte-v1_04_00'.
  - The element 'http://www.w3.org/2000/09/xmldsig#:Signature' is missing.

If you would like more help, please type "xsd /?".

C:\Reinf\XSD>xsd evtInfoContribuinte-v1_04_00.xsd /classes
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.6.1055.0]
Copyright (C) Microsoft Corporation. All rights reserved.
Schema validation warning: The 'http://www.w3.org/2000/09/xmldsig#:Signature' el
ement is not declared. Line 754, position 10.

Warning: Schema could not be validated. Class generation may fail or may produce
 incorrect results.

Error: Error generating classes for schema 'evtInfoContribuinte-v1_04_00'.
  - The element 'http://www.w3.org/2000/09/xmldsig#:Signature' is missing.

I understood that in XSD it is giving error here:

<xs:element ref="ds:Signature"/>

I removed this line and it worked.

My question: Would that be the correct procedure (remove)?
Since it is the XSD file provided by the IRS.

The generated classes would not be incomplete?

1 answer

2


You could download the file xmldsig-core-schema.xsd (you can achieve it, for example by downloading the eSocial Communication Package v1.5, in the briefcase \XSD\Eventos\RetornoEvento) and execute the command in this way:

xsd.exe /classes evtInfoContribuinte-v1_04_00.xsd xmldsig-core-schema.xsd

This would not give the error, and the resulting class would be created with all the components of the element Signature.

But, removing the line that refers to ds:Signature, as you did, it does not bring any side effect and in fact it is even better because it will leave the generated class less polluted, and, in practice, this element Signature will never be used on the object, since the signature must be generated from the full XML and already serialized.

XSD files are most commonly used for the validation of XML files, and, when it comes to validation, this element Signature is essential, it must exist in the final XML. But to create the classes, which will be used later for serialization, the Signature no need because it will never be used.

Taking advantage, the way I use the command xsd.exe it is so (I broke in several lines to be more readable, but it is a command only):

xsd /c /f /l:cs
    /u:http://www.reinf.esocial.gov.br/schemas/evtInfoContribuinte/v1_04_00
    /n:R1000
    evtInfoContribuinte-v1_04_00.xsd
  • /c is a nickname for /classes;
  • /f indicates that fields will be created (Fields) instead of properties (properties);
  • /l:cs indicates that the output language will be C#, but this is already the default;
  • /u:[uri] indicates the URI of namespace of the XSD you are importing (remember that in the case of Reinf, each event will have a different URI);
  • /n:[namespace] indicates your namespace in the target application.

EDITION

Tip: Place each schema converted into a specific namespace, because they all have the root element with the same name, Reinf, and when you add the second class schema already give conflict, if not in separate namespaces. You can put this first class (extracted from the schema evtInfoContribuinte-v1_04_00.xsd) in namespace R1000, using the option /n:R1000 on the command line, for example:

namespace R1000 {
    using System.Xml.Serialization;

    public partial class Reinf {
        public ReinfEvtInfoContri evtInfoContri;
    }

    // [...]
}

If the schema communication retornoLoteEventos-v1_04_00.xsd, can put you in the namespace RetornoLoteEventos, using the option /n:RetornoLoteEventos on the command line, and so on.

  • Generating the returnLoteEvents-v1_04_00.Cs from XSD, It generates in the generated class several duplicated references to these attributes: [System.CodeDom.Compiler.Generatedcodeattribute("xsd", "4.6.1055.0")] [System.Serializableattribute()] [System.Diagnostics.DebuggerStepThroughAttribute()]&#xA;[System.ComponentModel.DesignerCategoryAttribute("code")]&#xA;[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.reinf.esocial.gov.br/schemas/retornoLoteEventos/v1_04_00")]&#xA;.... Which results in build errors Is it normal to ? Generate these duplicities?

  • Another question: when generating the class by XSD.EXE are you setting a specific namespace for each XSD? I ask because some property names are already giving conflict of equal names.... Ex: The type "Tstatus" already contains a definition for "descRelature", where it has the same definition in returnsLoteEvents-v1_04_00.Cs and returnsTotalizerEvent-v1_04_00.Cs

  • 1

    Yes, it is normal for the tool to create all these attributes, but probably this is not what is giving duplication error (and this will already answer your other comment), what is probably giving duplication error is that the root element of all schemas is the Reinf, then in the second scheme you convert will already duplicate, and, yes, we use different namespaces, see the tip I gave you in item 2 of that other answer: EFD Reinf v1_04_00 - How to instantiate and populate all Event properties?

  • I edited my answer here to include that information.

  • Yes, it was very clear and the error corrected...

  • Good, I hope one day that answer will be useful for someone! ;-)

Show 1 more comment

Browser other questions tagged

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