XML Serialization

R

Random

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top