473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

generating xml for an object

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
Nov 20 '05 #1
8 1211
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


Nov 20 '05 #2
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


Nov 20 '05 #3
* "Noor" <no*******@softhome.net> scripsit:
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.


Keyword: Reflection.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
* "Noor" <no*******@softhome.net> scripsit:
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.


Keyword: Reflection.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
>
Keyword: Reflection


Herfried,

Would you mind showing us a small code sample of this suggestion?
Nov 20 '05 #6
>
Keyword: Reflection


Herfried,

Would you mind showing us a small code sample of this suggestion?
Nov 20 '05 #7
Thanks Tom ..

Im going to try this code.. will give you my feedback.
Noor

"Tom John" <ne**@leeksoft.com> wrote in message
news:l1********************************@4ax.com...
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

Nov 20 '05 #8
Yup.. it would much helpful for me if you show some code or atleast point to
some url.
I went to your website.. but it's not in english.. so cant understand
anything.

thanks
Noor
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eq*************@TK2MSFTNGP10.phx.gbl...
* "Noor" <no*******@softhome.net> scripsit:
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.


Keyword: Reflection.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Axel Straschil | last post by:
Hello! I was fooling around with creating classes for a module with eval, something like: MyModule.py: class Base: init(self, name): self._name = name
1
by: Jack Notarangelo | last post by:
Hello, I am interested in anyone's preference as to creating datasets in code vs generating them using the UI. I know typing is an advantage of the latter method. But any other information...
5
by: Jon Sequeira | last post by:
Does anyone know of a component or class that available for generating updategrams from custom business objects? Ideally I need something that parses a mapping schema, interrogates an object, and...
3
by: Raed Sawalha | last post by:
Hello when I serialize an object an error generated using this function public string SerializeObject(object oClassObject,System.Type oClassType) { XmlSerializer oSerializer = new...
2
by: RichardG | last post by:
I have an object data class that Inherits from a java class and implements System.Runtime.Serialization.ISerializable as I only need to transfer across three properties, string, array of objects...
1
by: louis_la_brocante | last post by:
Dear all, I am having trouble generating a client proxy for a webservice whose methods return a "complex" type. The type is complex in that it is a class whose members are a mix of primitive...
0
SammyB
by: SammyB | last post by:
These are some "random" thoughts about generating random numbers in Visual Basic. Wikipedia will give a better introduction than I, see http://en.wikipedia.org/wiki/Random_number_generator. ...
0
Sakalicek
by: Sakalicek | last post by:
Hi all, I have following problem in my application. I have Web Service and project which uses methods from this Web Service. I created proxy WsProxy by wsdl.exe and put it into that project. But...
4
by: chris.lyon | last post by:
I'm trying to generate visual python objects from django objects and therefore have objects called 'Ring' and 'Cylinder' as django objects and I want to create objects of those names in visual. I...
6
by: vinod allapu | last post by:
Hi boss, I have a gridview, bound to a datasource . Here i want to add columns dynamically containing empty textboxes. Number of columns are variant . The added columns are not bound to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.