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

1

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

  

EFD Reinf v1_04_00
link

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 understand that in XSD it is giving error here:

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

I removed this line and it worked.

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

Will not the generated classes be incomplete?

    
asked by anonymous 04.12.2018 / 20:09

1 answer

0

You could download the file xmldsig-core-schema.xsd (you can get it by, for example, downloading the eSocial Communication Package v1.5 , in the \XSD\Eventos\RetornoEvento folder) and run the command 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 components of the Signature element.

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

XSD files are usually most used for XML file validation, and for validation this Signature element is essential, it must exist in the final XML. But to create the classes, which will be used later for serialization, Signature is not needed because it will never be used.

Taking advantage of this, the way I use the xsd.exe command is like this (I broke several lines to be more readable, but it's a single command):

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 ( fields ) will be created instead of properties );
  • /l:cs indicates that the output language will be C #, but this is already the default;
  • /u:[uri] indicates the URI of the namespace of the XSD you are importing (remembering that in the case of Reinf, each event will have a different URI);
  • /n:[namespace] indicates your namespace in the target application.

EDITION

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

namespace R1000 {
    using System.Xml.Serialization;

    public partial class Reinf {
        public ReinfEvtInfoContri evtInfoContri;
    }

    // [...]
}

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

04.12.2018 / 20:55