XML Serialization

Discussion in 'ASP .Net' started by Random, Jul 27, 2004.

  1. Random

    Random Guest

    I have created a class that acts as a container for collections of other
    classes, and am using the IXMLSerializable interface to custom deserialize
    my XML into the class structure. Well, I got the base class and it's
    properties working like a charm, but am having difficulty with the other
    classes.

    My class structure mimics the XML very closely

    <Myxmldoc attr1="a" attr2="b" attr3="c">
    <subClass1 subattr1="aa" subattr2="bb" subattr3="cc"/>
    <subClass2 subattr1="aa" subattr2="bb" subattr3="cc"/>
    <subClass3 subattr1="aa" subattr2="bb" subattr3="cc"/>
    </Myxmldoc>

    So the classes are...

    Public Class Myclass
    Implements IXMLSerializable

    Public Property classattr1() as String
    ....
    End Property

    Public Property classattr2() as String
    ....
    End Property

    Public Property classattr3() as String
    ....
    End Property

    Public Function GetSchema() As XmlSchema
    Implements IXmlSerializable.GetSchema
    Return Nothing
    End Function

    Public Sub ReadXml(ByVal reader As XmlReader)
    Implements IXmlSerializable.ReadXml
    classattr1 = reader.GetAttribute("attr1")
    classattr2 = reader.GetAttribute("attr3")
    classattr3 = reader.GetAttribute("attr3")
    End Sub

    Public Sub WriteXml(ByVal writer As XmlWriter)
    Implements IXmlSerializable.WriteXml
    .....
    End Sub
    End Class

    Public Class Mysubclass
    Implements IXMLSerializable

    Public Property subclassattr1() as String
    ....
    End Property

    Public Property subclassattr2() as String
    ....
    End Property

    Public Property subclassattr3() as String
    ....
    End Property

    Public Function GetSchema() As XmlSchema
    Implements IXmlSerializable.GetSchema
    Return Nothing
    End Function

    Public Sub ReadXml(ByVal reader As XmlReader)
    Implements IXmlSerializable.ReadXml
    subclassattr1 = reader.GetAttribute("subattr1")
    subclassattr2 = reader.GetAttribute("subattr3")
    subclassattr3 = reader.GetAttribute("subattr3")
    End Sub

    Public Sub WriteXml(ByVal writer As XmlWriter)
    Implements IXmlSerializable.WriteXml
    .....
    End Sub
    End Class
     
    Random, Jul 27, 2004
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.