0

I have two types of file XML that share some common information but also have some specialization:

<Source Alias="Hrc">
   <Variable HandleType="Ext.Poll">
      <Id>ConfiguredTime</Id>
      <Type>Double</Type>
      <SamplingDimension>15</SamplingDimension>
      <MappedData>Main.Section.Child.BaseBoardLoader[1].IS.Reports.Absolute.ConfiguredTime</MappedData>
   </Variable>
</Source>






<Source Alias="Wrt">
   <Variable>
      <Id>Identification.ProductInstanceUri</Id>
      <Type>String</Type>
      <MappedData EfficientAccess="true">
         <RtdbItem>
            <TableName>IDENTIFICATION</TableName>
            <DataName>ProductInstanceU</DataName>
            <Record>0</Record>
         </RtdbItem>        
      </MappedData>
   </Variable>
</Source>

In this example Source and Variable are the same, while MappedVariable can be string or object type. How can I structure classes for automatic serialize XML?

I've create classes with Paste XML as Classes function of VisualStudio. But don't help me.

4
  • Just include all the properties from both type in the Variable class. Some properties may be empty but that should no affect anything. Commented Dec 16, 2023 at 11:39
  • The problem is that MappedData sometimes is string sometimes is complex object. I cannot specify a property with same name but different types Commented Dec 16, 2023 at 13:40
  • You may need to use a IXmlSerializer : learn.microsoft.com/en-us/dotnet/api/… What you have posted does not need the IXmlSerializer. You have 3 properties 1) Attribute EfficientAccess 2) Text 3) Class RtdbItem Commented Dec 16, 2023 at 14:15
  • Thank you so much. I set 3 properties as you suggest. Commented Dec 20, 2023 at 10:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.