How can I ignore certain fields conditionally on XML serialization

I'm trying to write a program that should serialize a class to an XML file, but recently my spec has changed and now I have a previously unique and not null field like this:

  • The usual case, as before, the fields do not change [a, b, c]
  • n fields with a link to another field id [a, b, c, id]

How can I change my class to allow this behavior?

Actual:

    <Serializable>
    Public Class DataType
        Public FieldToChange As New FieldType 'FieldType to change
    End Class

    <Serializable>
    Public class FieldType
        Public a As Integer
        Public b As Integer
        Public c As Integer
    End Class

      

Future:

    <Serializable>
    Public Class ClassWithElemToChangeType
        <XmlElement("FieldType")> ' Is it right?
        Public FieldToChange As New List(Of FieldType)
    End Class

    <Serializable>
    Public class FieldType
        Public a As Integer
        Public b As Integer
        Public c As Integer
        Public id As Integer
        ' How can i add a field that gets ignored whenever is null
        ' or how can I programmatically tell my serializer to ignore
    End Class

      

+3
xml serialization vb.net


source to share


No one has answered this question yet

See similar questions:

61
Suppress null value types from emitting XmlSerializer

or similar:

2024
How do you parse and process HTML / XML in PHP?
863
How do I process XML in Python?
749
How to comment out a tag block in XML?
442
How to deserialize an XML document
1
Read SOAP XML with ASMX web servcie function
0
Custom XML element name for base class field in serialization
0
Object to XML serialization issue in VB.Net
0
Serialize XML and ignore objects without value
0
Failed to add new xml property for serialization
0
Serializing to XML with XStream, but not getting all fields



All Articles
Loading...
X
Show
Funny
Dev
Pics