0

I have an XSD file and I used the xsd 2 code tool to generate the code for this XSD. When the XML file first create (before I give values) it contains some elements and values. My question is where does those values come from and how can I just start with empty elements.

Here is the code

  private void XMLEF15ItemClick(object sender, ItemClickEventArgs e)
    {
        try
        {
            SaveFileDialog saveFile = new SaveFileDialog
            {
                FileName = "EF15 " + DefkCurrent.ArithmosAnaforas_7,
                Filter = "XML (*.xml)|*.xml",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            };

            EmcsMessage ecs = new EmcsMessage(DefkCurrent);
            EF15 ef15Msg = ecs.CreateEF15();

            if (saveFile.ShowDialog(this).Equals(DialogResult.OK))
            {
                ef15Msg.SaveToFile(saveFile.FileName);

                MessageSuccess("ΔΕΦΚ - EF15");
            }
        }
        catch (CreateMessageException ex)
        {
            using (DiskErrorsForm diskErrorsForm = new DiskErrorsForm(ex.Errors))
            {
                diskErrorsForm.ShowDialog(this);
            }
        }
    }

Here is the EF15

  private Defk DefkCurrent { get; set; }
    private StringBuilder ErrorBuilder { get; set; }
    private EF15AType MessageIF15 { get; set; }

    public EF15(Defk defk)
    {
        DefkCurrent = defk;
        MessageIF15 = new EF15AType();
        LengthWarn.WarnBuilder = new StringBuilder();
    }

  public EF15.EF15 CreateEF15()
    {
        EF15.EF15 message = new EF15.EF15(DefkCurrent);

        message.Create();

        return message;
    }

and here is the part of the generated code from XSD(IT is quite big to paste it all ,around 9000 lines)

  public EF15AType() {
        this.bodyField = new BodyType();
        this.headerField = new HeaderType();
    }

When code reach in EF15.EF15 message = new EF15.EF15(DefkCurrent); it already has create a part of the XML with this content (which I havent gave any values)

{<?xml version="1.0" encoding="utf-8"?>

<Header>
    <DateOfPreparation xmlns="http://www.icisnet.gr/emcs/v1.03/tms">0001-01-01</DateOfPreparation>
    <TimeOfPreparation xmlns="http://www.icisnet.gr/emcs/v1.03/tms">00:00:00.0000000+02:00</TimeOfPreparation>
</Header>
<Body>
    <DeclarationOfExciseTaxesRegistration>
        <SubmittingOperator />
        <ExciseTaxesDeclaration>
            <Fallbackflag>0</Fallbackflag>
            <DocumentState>0</DocumentState>
            <PaymentMethodCode>A</PaymentMethodCode>
            <DeclarationTypeCode>30</DeclarationTypeCode>
            <GeneralChemistryDetails />
            <DeliveryDetails />
            <ClearingAgent>
                <ClearingAgentType>1</ClearingAgentType>
            </ClearingAgent>
        </ExciseTaxesDeclaration>
        <ExciseTaxesDeclarationConsignor>
            <ExciseTaxesDeclarationConsignorType>0</ExciseTaxesDeclarationConsignorType>
        </ExciseTaxesDeclarationConsignor>
        <ExciseTaxesObligee>
            <ObligeeType>1</ObligeeType>
            <ContactDetails />
        </ExciseTaxesObligee>
        <ExciseTaxesDeclarationConsignee>
            <ConsigneeType>0</ConsigneeType>
            <ConsigneeIdentificationType>1</ConsigneeIdentificationType>
            <ContactDetails />
            <SpecialConsignee>
                <SpecialConsigneeLicenseType>1</SpecialConsigneeLicenseType>
            </SpecialConsignee>
            <VesselRegistrationDetails>
                <VesselRegistrationType>1</VesselRegistrationType>
            </VesselRegistrationDetails>
        </ExciseTaxesDeclarationConsignee>
    </DeclarationOfExciseTaxesRegistration>
</Body>

}

If someone can help me or need more of the code please tell me. Thans in advance.

rippergr
  • 182
  • 2
  • 20
  • It appears that one of these two instructions are add the data : EF15.EF15 message = new EF15.EF15(DefkCurrent); or message.Create(); – jdweng Dec 03 '17 at 10:00
  • in message.Create I add the values that I want. In EF15.EF15 message = new EF15.EF15(DefkCurrent) it adds the data but I don't give any values – rippergr Dec 03 '17 at 10:18
  • So you just answered your own question. The values are coming from the Create() method. It you do not want values then do not call the Create() method just call the constructor new. – jdweng Dec 03 '17 at 10:34
  • The create method is after the EF15.EF15 message = new EF15.EF15(DefkCurrent). The XML is created in that method and is takes some elements and values somehow without set them myself – rippergr Dec 03 '17 at 10:37
  • class EF15 cannot have a property EF15 so I'm not sure how this compiles. – jdweng Dec 03 '17 at 13:00
  • I have more classes like that that do the same thing. Only this XML takes some values without declaring them. – rippergr Dec 03 '17 at 18:57
  • I believe there is something wrong with the xsd2code . When the starts serializing the XML it goes through some constructors (body,header,excisetaxesdeclaration etc.) Some of those constructors have some tpes like date or item and when it initializing them it takes the first item or if it's a date it gets 01-01-0001 – rippergr Dec 06 '17 at 15:35
  • So isn't that the answer why the class contains data and is not empty. The questions was : "My question is where does those values come from and how can I just start with empty elements?" What you can do is add a parameter to the constructor true/false to initialize or not initialize. Probably the schema check will fail without proper values. – jdweng Dec 06 '17 at 15:44
  • Yes I thought that maybe the xsd schema needs those values so I changed the generated cs code appropriate. My problem was that I didn't wan't to change the xsd or the generated code because those xsd come from an official source so if someday they change the file I have to remember and change everything I changed. – rippergr Dec 12 '17 at 20:10

0 Answers0