Noor
You could use Serialization to convert the class into XML, use import
the namespace System.Xml.Serialization, then mark your class
Serializable:
<Serializable()> Public Class MyClass
Dim mText As String
Public Property Tags() As String
Get
Return mText
End Get
Set(ByVal Value As String)
mText= Value
End Set
End Property
End Class
Then to save the object:
Private Sub SaveObject()
Dim MyObject As New MyClass()
Dim Seralizer As New XmlSerializer(GetType(MyClass))
Dim XmlFile As New FileStream("C:\Temp\MyFile", _
FileMode.Create, FileAccess.Write)
Dim XmlWriter As New XmlTextWriter(XmlFile, Nothing)
Seralizer.Serialize(XmlWriter, MyObjec )
XmlWriter.Close()
XmlFile.Close()
XmlFile = Nothing
End Sub
And to load the object:
Public Sub LoadObject ()
Dim Seralizer As New XmlSerializer(GetType(MyClass))
Dim XmlFile As New FileStream("C:\Temp\MyFile", _
FileMode.Open, FileAccess.Read)
Dim XmlReader As New XmlTextReader(XmlFile)
Dim MyObject as MyClass = _
CType(Seralizer.Deserialize(XmlReader), MyClass)
XmlReader.Close()
XmlFile.Close()
End Sub
Hope this helps....
Tom
On Mon, 12 Jan 2004 13:01:07 +0500, "Noor" <no*******@softhome.net>
wrote:
Hi all.
I need to generate xml for a class object....
I know i can generate it if i know all the fields for an object.
but i want to create a generic routice for it.. means a routine that will
take a class object and parse and extract out all the properites with the
data and write its xml representation.
how can i do this in .net
any idea? tutorial ?
regards,
Noor