Can I make a class from XML? Serialize?

Discussion in 'ASP .Net' started by Jonah Olsson, Aug 8, 2003.

  1. Jonah Olsson

    Jonah Olsson Guest

    Hi guys,

    I need a way to dynamically change (or create) a custom class using an
    external xml file. Can this be done at all? This is what the class looks
    like:

    Public Class MemberData
    Private _EmailGUID As String
    Private _Email As String
    Private _FirstName As String
    Private _LastName As String
    Private _Title As String
    Private _Company As String
    Private _Address As String
    Private _PostalCode As Integer
    Private _City As String
    Private _Phone As String
    Private _Active As Integer
    Private _RegDate As DateTime
    Private _ChangeDate As DateTime

    Public Sub New()
    MyBase.New()

    _EmailGUID = ""
    _Email = ""
    _FirstName = ""
    _LastName = ""
    _Title = ""
    _Company = ""
    _Address = ""
    _PostalCode = 0
    _City = ""
    _Phone = ""
    _Active = 0
    _RegDate = Nothing
    _ChangeDate = Nothing
    _SoftBounces = 0
    _HardBounces = 0
    _GroupIDs = ""

    End Sub

    Public Property EmailGUID() As String
    Get
    Return _EmailGUID
    End Get
    Set(ByVal Value As String)
    If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
    Throw New Exception("The email address identifier cannot be
    empty")
    End If
    _EmailGUID = Value
    End Set
    End Property

    Public Property Email() As String
    Get
    Return _Email
    End Get
    Set(ByVal Value As String)
    If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
    Throw New Exception("The email address cannot be empty")
    End If
    _Email = Value
    End Set
    End Property

    [...]

    End Class


    Thanks.
    Regards Jonah
    Jonah Olsson, Aug 8, 2003
    #1
    1. Advertising

  2. Jonah Olsson

    Nak Guest

    Hi there,

    Do you mean during Run-time? If so then I don't believe so. Or do you
    mean at Design-time? If so then it is "possible" but you would need to
    either find an application that can create a class from an XML file or make
    one yourself, out of interest what purpose would it serve?

    Nick.

    "Jonah Olsson" <> wrote in message
    news:%23HUU$...
    > Hi guys,
    >
    > I need a way to dynamically change (or create) a custom class using an
    > external xml file. Can this be done at all? This is what the class looks
    > like:
    >
    > Public Class MemberData
    > Private _EmailGUID As String
    > Private _Email As String
    > Private _FirstName As String
    > Private _LastName As String
    > Private _Title As String
    > Private _Company As String
    > Private _Address As String
    > Private _PostalCode As Integer
    > Private _City As String
    > Private _Phone As String
    > Private _Active As Integer
    > Private _RegDate As DateTime
    > Private _ChangeDate As DateTime
    >
    > Public Sub New()
    > MyBase.New()
    >
    > _EmailGUID = ""
    > _Email = ""
    > _FirstName = ""
    > _LastName = ""
    > _Title = ""
    > _Company = ""
    > _Address = ""
    > _PostalCode = 0
    > _City = ""
    > _Phone = ""
    > _Active = 0
    > _RegDate = Nothing
    > _ChangeDate = Nothing
    > _SoftBounces = 0
    > _HardBounces = 0
    > _GroupIDs = ""
    >
    > End Sub
    >
    > Public Property EmailGUID() As String
    > Get
    > Return _EmailGUID
    > End Get
    > Set(ByVal Value As String)
    > If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
    > Throw New Exception("The email address identifier cannot

    be
    > empty")
    > End If
    > _EmailGUID = Value
    > End Set
    > End Property
    >
    > Public Property Email() As String
    > Get
    > Return _Email
    > End Get
    > Set(ByVal Value As String)
    > If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
    > Throw New Exception("The email address cannot be empty")
    > End If
    > _Email = Value
    > End Set
    > End Property
    >
    > [...]
    >
    > End Class
    >
    >
    > Thanks.
    > Regards Jonah
    >
    >
    Nak, Aug 8, 2003
    #2
    1. Advertising

  3. Jonah Olsson

    Jonah Olsson Guest

    Hi Nick,

    Here's the deal; I'm trying to create a Web Service to be run as an engine
    for several client web applications. The engine takes care of all
    communication with each database.
    The reason I say 'each' is that a customer may use their own SQL server. All
    this is just testing, but I came up with the idea when looking at an example
    how to dynamically create stored procedures using XML files
    (http://www.fawcette.com/xmlmag/2002_11/online/xml_wahlin_11_05_02/). Since
    I use the MemberData class in the function that contains the call to the
    Stored Procedure, and I can change the parameters in the SP using an XML
    file, why shouldn't I be able to also make the MemberData class dynamic.

    Say, one customer needs to add "Department" to the MemberData class. This
    can easily be done in the XML file for the SP, but how to add it to the
    MemberData class? I just don't want to re-build the entire Web Service
    application.

    I'm not sure though if I explained this so people can understand me... =)

    Jonah

    "Nak" <> skrev i meddelandet
    news:...
    > Hi there,
    >
    > Do you mean during Run-time? If so then I don't believe so. Or do you
    > mean at Design-time? If so then it is "possible" but you would need to
    > either find an application that can create a class from an XML file or

    make
    > one yourself, out of interest what purpose would it serve?
    >
    > Nick.
    Jonah Olsson, Aug 8, 2003
    #3
  4. Jonah Olsson

    yoz Guest

    I am not sure if you want to do it at runtime, but if you do, create a C#
    class from the XML (hey you can even do it with XSLT ;-) and use the free
    csc.exe (C# compiler) in your windows/Microsoft.NET folder to compile.

    If you really want to make things hard for yourself, I know (heard) there
    are helper classes to create Assemblies straight without code. I don't have
    the book with me, but they seem to exists. naaaaaa, option 1 would be far
    cheaper.

    Yoz

    "Jonah Olsson" <> wrote in message
    news:%23HUU$...
    > Hi guys,
    >
    > I need a way to dynamically change (or create) a custom class using an
    > external xml file. Can this be done at all? This is what the class looks
    > like:
    >
    > Public Class MemberData
    > Private _EmailGUID As String
    > Private _Email As String
    > Private _FirstName As String
    > Private _LastName As String
    > Private _Title As String
    > Private _Company As String
    > Private _Address As String
    > Private _PostalCode As Integer
    > Private _City As String
    > Private _Phone As String
    > Private _Active As Integer
    > Private _RegDate As DateTime
    > Private _ChangeDate As DateTime
    >
    > Public Sub New()
    > MyBase.New()
    >
    > _EmailGUID = ""
    > _Email = ""
    > _FirstName = ""
    > _LastName = ""
    > _Title = ""
    > _Company = ""
    > _Address = ""
    > _PostalCode = 0
    > _City = ""
    > _Phone = ""
    > _Active = 0
    > _RegDate = Nothing
    > _ChangeDate = Nothing
    > _SoftBounces = 0
    > _HardBounces = 0
    > _GroupIDs = ""
    >
    > End Sub
    >
    > Public Property EmailGUID() As String
    > Get
    > Return _EmailGUID
    > End Get
    > Set(ByVal Value As String)
    > If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
    > Throw New Exception("The email address identifier cannot

    be
    > empty")
    > End If
    > _EmailGUID = Value
    > End Set
    > End Property
    >
    > Public Property Email() As String
    > Get
    > Return _Email
    > End Get
    > Set(ByVal Value As String)
    > If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
    > Throw New Exception("The email address cannot be empty")
    > End If
    > _Email = Value
    > End Set
    > End Property
    >
    > [...]
    >
    > End Class
    >
    >
    > Thanks.
    > Regards Jonah
    >
    >
    yoz, Aug 8, 2003
    #4
  5. Jonah Olsson

    Nak Guest

    Hi Jonah,

    Sorry I have no idea about Web Services at the moment, I haven't gotten
    into any of that. But by the sounds of things I am sure that you can make
    the engine that you want, I just do not have the knowledge in that field to
    provide enough assistance, sorry :-( Maybe someone else will offer advice
    here.

    Nick.

    "Jonah Olsson" <> wrote in message
    news:...
    > Hi Nick,
    >
    > Here's the deal; I'm trying to create a Web Service to be run as an engine
    > for several client web applications. The engine takes care of all
    > communication with each database.
    > The reason I say 'each' is that a customer may use their own SQL server.

    All
    > this is just testing, but I came up with the idea when looking at an

    example
    > how to dynamically create stored procedures using XML files
    > (http://www.fawcette.com/xmlmag/2002_11/online/xml_wahlin_11_05_02/).

    Since
    > I use the MemberData class in the function that contains the call to the
    > Stored Procedure, and I can change the parameters in the SP using an XML
    > file, why shouldn't I be able to also make the MemberData class dynamic.
    >
    > Say, one customer needs to add "Department" to the MemberData class. This
    > can easily be done in the XML file for the SP, but how to add it to the
    > MemberData class? I just don't want to re-build the entire Web Service
    > application.
    >
    > I'm not sure though if I explained this so people can understand me... =)
    >
    > Jonah
    >
    > "Nak" <> skrev i meddelandet
    > news:...
    > > Hi there,
    > >
    > > Do you mean during Run-time? If so then I don't believe so. Or do

    you
    > > mean at Design-time? If so then it is "possible" but you would need to
    > > either find an application that can create a class from an XML file or

    > make
    > > one yourself, out of interest what purpose would it serve?
    > >
    > > Nick.

    >
    >
    Nak, Aug 8, 2003
    #5
  6. Jonah Olsson

    yoz Guest

    What you seem to want is to create dynamic web services where you would
    specify an xml and it will create a web service that will be mediating
    between the database and the client. I am making this assumption for the
    rest of the mail.

    1) you create an object that mirror the table (or your xml will have to map
    database field to .NET Class field) in a C# code and compile it with csc.

    2) then you create an object with methods such as Select which returns an
    array of the type you created in step 1. You compile this also in another
    assembly (maybe you can combine both into one assembly?)

    Either:

    3a) Make it available via a Remote Object

    http://msdn.microsoft.com/architect...l=/library/en-us/dnnetsec/html/SecNetHT15.asp

    The executable could be a remote service.

    or

    3b) you can create an asmx to put on IIS that provides the Soap Service.

    Hopes that help, I am just think aloud here...


    There is a tool called Program Files\Microsoft.NET\SDK\v1.1\Bin\SoapSuds.exe
    (look on google for "soapsuds"). Have a look at it, it may help.

    http://msdn.microsoft.com/library/d...ools/html/cpgrfsoapsudsutilitysoapsudsexe.asp

    PS: You can also have a thread that look for change in XML to regenerate
    what has changed. You can even work of a database schema. good luck.


    "Jonah Olsson" <> wrote in message
    news:%...
    > Hi Yoz,
    >
    > ..and maybe I'm in deep water :)
    > Should I reconsider the entire design? Maybe each client web application

    has
    > to be custom built to match their database? What do you suggest?
    >
    > Thanks
    > Jonah
    >
    >
    > "yoz" <netfever@hot_REMOVE_SPAM_mail.com> skrev i meddelandet
    > news:XHUYa.8911$...
    > > I am not sure if you want to do it at runtime, but if you do, create a

    C#
    > > class from the XML (hey you can even do it with XSLT ;-) and use the

    free
    > > csc.exe (C# compiler) in your windows/Microsoft.NET folder to compile.
    > >
    > > If you really want to make things hard for yourself, I know (heard)

    there
    > > are helper classes to create Assemblies straight without code. I don't

    > have
    > > the book with me, but they seem to exists. naaaaaa, option 1 would be

    far
    > > cheaper.

    >
    >
    yoz, Aug 8, 2003
    #6
  7. Jonah Olsson

    Jonah Olsson Guest

    Thanks anyway Nick! :)

    Jonah

    "Nak" <> skrev i meddelandet
    news:...
    > Hi Jonah,
    >
    > Sorry I have no idea about Web Services at the moment, I haven't

    gotten
    > into any of that. But by the sounds of things I am sure that you can make
    > the engine that you want, I just do not have the knowledge in that field

    to
    > provide enough assistance, sorry :-( Maybe someone else will offer advice
    > here.
    >
    > Nick.
    Jonah Olsson, Aug 8, 2003
    #7
  8. Jonah Olsson

    Jonah Olsson Guest

    Thanks Yoz!
    Your information seems very interesting and I'll start digging into it first
    thing tomorrow morning.

    Jonah
    Jonah Olsson, Aug 9, 2003
    #8
  9. Jonah Olsson

    Cor Guest

    Jonah,
    It seems clear, but it is not for me, you say a Web Service to run as an
    engine (Webservice?) for several client web applications. There is a lot of
    difference in that. When it is a webService who runs on side A and then
    takes action on Side B will be very complex with authoring, but maybe I see
    things wrong.

    Like Nick I do not know if I can help you, I do know very few from SQL but
    maybe this group can help you together.

    And of course, when this solution can made with C# it can be made better
    with VB.Net.

    Cor









    "Jonah Olsson" <> schreef in bericht
    news:...
    > Hi Nick,
    >
    > Here's the deal; I'm trying to create a Web Service to be run as an engine
    > for several client web applications. The engine takes care of all
    > communication with each database.
    > The reason I say 'each' is that a customer may use their own SQL server.

    All
    > this is just testing, but I came up with the idea when looking at an

    example
    > how to dynamically create stored procedures using XML files
    > (http://www.fawcette.com/xmlmag/2002_11/online/xml_wahlin_11_05_02/).

    Since
    > I use the MemberData class in the function that contains the call to the
    > Stored Procedure, and I can change the parameters in the SP using an XML
    > file, why shouldn't I be able to also make the MemberData class dynamic.
    >
    > Say, one customer needs to add "Department" to the MemberData class. This
    > can easily be done in the XML file for the SP, but how to add it to the
    > MemberData class? I just don't want to re-build the entire Web Service
    > application.
    >
    > I'm not sure though if I explained this so people can understand me... =)
    >
    > Jonah
    >
    > "Nak" <> skrev i meddelandet
    > news:...
    > > Hi there,
    > >
    > > Do you mean during Run-time? If so then I don't believe so. Or do

    you
    > > mean at Design-time? If so then it is "possible" but you would need to
    > > either find an application that can create a class from an XML file or

    > make
    > > one yourself, out of interest what purpose would it serve?
    > >
    > > Nick.

    >
    >
    Cor, Aug 9, 2003
    #9
  10. Jonah Olsson

    yoz Guest

    "Cor" <> wrote in message
    news:3f34e3a6$0$19739$...
    > And of course, when this solution can made with C# it can be made better
    > with VB.Net.


    better with vb.net??
    yoz, Aug 9, 2003
    #10
  11. Jonah Olsson

    Cor Guest

    Jonah,
    Lets make it simple for me.
    You need a class, that you implement in your Soap Webservices to talk with
    your SQL server on Site A and changes messages with the clients via SOAP.

    That is in mine opinion the standaard VB.Net Webservices Application
    described in the walkthrough "Creating a distributed Application". For me is
    the webservices side of this application is a class by itself but maybe I am
    wrong. When you use this example, I think then you only have to add your own
    SQL procedures and it is done.

    And what about vb.net I did not see that it was crossposted and yoz said
    that you could make a C# application, so I thought why. Till now I am
    intrested in what I cannot make easier with VB.Net than with C# (VB.net
    has more functions, standard things like collection etc).
    Cor
    Cor, Aug 9, 2003
    #11
  12. Jonah Olsson

    yoz Guest

    "Cor" <> wrote in message
    news:3f34fe81$0$19749$...
    > And what about vb.net I did not see that it was crossposted and yoz said
    > that you could make a C# application, so I thought why. Till now I am
    > intrested in what I cannot make easier with VB.Net than with C# (VB.net
    > has more functions, standard things like collection etc).
    > Cor


    Here we go, the religious debate that never ends. Once upon a time, there
    was same debate between C++ and VB and fortunately, the answer came from
    Borland: Delphi.

    As for VB.net, there are functionality, or should I say VB routines that
    have been carried out into .NET but they are not always efficient and most
    are easily reproducible in C#. For example, the IsNumeric function is not in
    C# but you can make a more efficient one (ever look at the length of the
    code) or use the Microsoft.VisualBasic assembly which will provide it to
    you.

    I suppose in a way, it does not matter under .NET which language you use,
    but what will matter is the organization of the code. Large commercial
    projects, large open source projects are very likely to use Java or C rather
    than Basic. Like it or not, in my experience (in my part of the world) Basic
    is still seen as a toy, a beginner language. The fact that the assembly
    generated are similar between those languages have not registered. There is
    also a way of thinking that VB people know less about the internals than C#
    people who knows less than IL ASM developers.
    yoz, Aug 9, 2003
    #12
  13. Jonah Olsson

    Cor Guest

    We agree yoz, was a misunderstanding from me.
    And what the so known profesionals say, in all history it was so that the
    tool that makes the best product always wins.
    And that is not from the last 50 years.
    Cor
    Cor, Aug 9, 2003
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gordz
    Replies:
    3
    Views:
    3,932
    John Oakes
    Jun 7, 2004
  2. Neil
    Replies:
    4
    Views:
    1,516
    Mike Schilling
    Sep 28, 2009
  3. Schneider

    serialize a class to XML and back

    Schneider, May 23, 2013, in forum: Python
    Replies:
    1
    Views:
    104
    alex23
    May 24, 2013
  4. Burak Arslan

    Re: serialize a class to XML and back

    Burak Arslan, May 23, 2013, in forum: Python
    Replies:
    0
    Views:
    85
    Burak Arslan
    May 23, 2013
  5. dieter
    Replies:
    0
    Views:
    97
    dieter
    May 25, 2013
Loading...

Share This Page