[XML Records] RecordListToXml issues with serialization of XML

[XML Records] RecordListToXml issues with serialization of XML

  
Forge Component
(29)
Published on 5 Feb by Afonso Carvalho
29 votes
Published on 5 Feb by Afonso Carvalho

Hi all,

Following the issue resolved on XmlToRecordList issues with deserialization of XML i tried to do a RecordListToXml but the result wasn't the same.

Original:

<informacao_economica>
    <justificacao />
    <sem_info_financeira>False</sem_info_financeira>
    <imobilizacoes_incorporeas>
      <valor>210</valor>
      <valor>10</valor>
      <valor>10</valor>
    </imobilizacoes_incorporeas>
<previsionais>False</previsionais>
<reais>False</reais>
</informacao_economica>


Result of RecordListToXml:

<informacao_economica>
  <justificacao>Teste XML Record com valor</justificacao>
  <sem_info_financeira>False</sem_info_financeira>
  <imobilizacoes_incorporeas>
    <valor>
      <valor>210</valor>
    </valor>
    <valor>
      <valor>10</valor>
    </valor>
    <valor>
      <valor>10</valor>
    </valor>
  </imobilizacoes_incorporeas>
  <previsionais>False</previsionais>
  <reais>True</reais>
</informacao_economica>


What am I missing in here?


Regards,

Abílio Matos

Abilio Matos wrote:

Hi all,

Following the issue resolved on XmlToRecordList issues with deserialization of XML i tried to do a RecordListToXml but the result wasn't the same.

Original:

<informacao_economica>
    <justificacao />
    <sem_info_financeira>False</sem_info_financeira>
    <imobilizacoes_incorporeas>
      <valor>210</valor>
      <valor>10</valor>
      <valor>10</valor>
    </imobilizacoes_incorporeas>
<previsionais>False</previsionais>
<reais>False</reais>
</informacao_economica>


Result of RecordListToXml:

<informacao_economica>
  <justificacao>Teste XML Record com valor</justificacao>
  <sem_info_financeira>False</sem_info_financeira>
  <imobilizacoes_incorporeas>
    <valor>
      <valor>210</valor>
    </valor>
    <valor>
      <valor>10</valor>
    </valor>
    <valor>
      <valor>10</valor>
    </valor>
  </imobilizacoes_incorporeas>
  <previsionais>False</previsionais>
  <reais>True</reais>
</informacao_economica>


What am I missing in here?


Regards,

Abílio Matos

What is type of valor tag in your structure.?


Hi, 

the valor tag is of type integer. But the problem here is that the RecordListToXML doesn't return the same xml format that was originally received by XmlToRecordList.


Best Regards,

Abílio Matos

Solution

Hi Abílio, I'm sending you a solution in attach. The only thing I did was to add the prefix Cont_ to the name of the attribute valor in the structure valor

Why does it work? 

 the XmlToRecordList and the RecordListToXml assume a default configuration. According to this configuration, an attribute starting with the prefix Cont_ is assumed to have the content of the record. Therefore, the name of the attribute is discarded when serialising to or deserialising from xml. You can change this default behaviour if you want to. The only thing you need to do is to create a variable of type DefaultXmlConfig and set the value of the attribute of the ContentPrefix attribute to something else. Its default value is Cont_.

Solution

Pedro,


Thanks again for your help. It really solved it. 

Seems I need to spend a little more time understanding the DefaultXmlConfig and his settings.


Abílio Matos