Generate C# class from XSD

Asked

Viewed 2,079 times

1

I need to generate the class from a file. XSD.

Though I’ve tried everything I know (used . net tool: xsd.exe, httputility.net and other . Cs generators) did not succeed.

I think the mistake is in the schema they gave me, but I can’t identify what the problem is. Can anyone help? Thanks in advance.

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.cnj.jus.br/replicacao-nacional"
elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:cnj="http://www.cnj.jus.br/intercomunicacao-2.2.2" xmlns:xmime="http://www.w3.org/2005/05/xmlmime">

<import schemaLocation="http://www.cnj.jus.br/images/dti/Comite_Gestao_TIC/Modelo_Nacional_Interoperabilidade/versao_07_07_2014/intercomunicacao-2.2.2.xsd"
    namespace="http://www.cnj.jus.br/intercomunicacao-2.2.2"></import>

<element name="processos">
    <complexType>
        <sequence>
            <element minOccurs="1" maxOccurs="unbounded" name="processo" type="cnj:tipoProcessoJudicial" />
        </sequence>
    </complexType>
</element>
</schema>
  • I executed your code on the site http://www.httputility.net/xsd-to-csharp-vb-class.aspx and see what error you got: Type 'http://www.cnj.jus.br/intercomunicacao-2.2.2:tipProcessoJudicial' is not declared. Your xsd is incomplete.

  • This command line can be used to generate the Classes, having the NF-e Schemas: See https://answall.com/a/218780/5704

1 answer

2


Do the following:

  • Save the file xsd (http://www.cnj.jus.br/images/dti/Comite_Gestao_TIC/Modelo_Nacional_Interoperabilidade/versao_07_07_2014/intercomunicacao-2.2.2.xsd) on your computer.
  • Edit the file and remove first line <?xml version="1.0" encoding="UTF-8"?> and save.
  • Now you can use the file to generate the classe.

See part of the generated file:

namespace AutoGeneratedCode
{

   /// 
   [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34283")]
   [System.SerializableAttribute()]
   [System.Diagnostics.DebuggerStepThroughAttribute()]
   [System.ComponentModel.DesignerCategoryAttribute("code")]
   [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.cnj.jus.br/intercomunicacao-2.2.2")]
   [System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.cnj.jus.br/intercomunicacao-2.2.2", IsNullable=true)]
   public partial class tipoEndereco
   {
      private string logradouroField;
      private string numeroField;
      private string complementoField;
      private string bairroField;
      private string cidadeField;
      private string estadoField;
      private string paisField;
      private string cepField;
      /// 

Browser other questions tagged

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