initializing objects via an xml file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe Abou Jaoude

    #1

    initializing objects via an xml file



    Hi,

    I want to initialize a number of objects via an xml file, and I was
    wondering if that can be done through a section in the app.config file
    without the need to use another config file.

    example:
    if we have the class:
    Public Class myClass

    Public property prop1
    Public property prop2

    ....

    End Class

    the config file would be something like this:
    <config>
    <MyClass>
    <prop1>abc</prop1>
    <prop2>xyz</prop2>
    </MyClass>
    <MyClass>
    <prop1>deg</prop1>
    <prop2>klm</prop2>
    </MyClass>
    </config>

    is there a way to do that in the app.config file ?

    Thank you


    *** Sent via Developersdex http://www.developersdex.com ***
  • rowe_newsgroups

    #2
    Re: initializing objects via an xml file

    On May 24, 2:39 am, Joe Abou Jaoude <anonym...@devd ex.comwrote:
    Hi,
    >
    I want to initialize a number of objects via an xml file, and I was
    wondering if that can be done through a section in the app.config file
    without the need to use another config file.
    >
    example:
    if we have the class:
    Public Class myClass
    >
    Public property prop1
    Public property prop2
    >
    ...
    >
    End Class
    >
    the config file would be something like this:
    <config>
    <MyClass>
    <prop1>abc</prop1>
    <prop2>xyz</prop2>
    </MyClass>
    <MyClass>
    <prop1>deg</prop1>
    <prop2>klm</prop2>
    </MyClass>
    </config>
    >
    is there a way to do that in the app.config file ?
    >
    Thank you
    >
    *** Sent via Developersdexht tp://www.developersd ex.com***
    is there a way to do that in the app.config file ?
    I don't think there is an automatic way of doing this, but you could
    easily write a procedure to grab the values from the app.config file
    and assign them to class's properties. Everything you need should be
    in the System.Xml namespace.

    Thanks,

    Seth Rowe

    Comment

    • Chris Dunaway

      #3
      Re: initializing objects via an xml file

      On May 24, 5:59 am, rowe_newsgroups <rowe_em...@yah oo.comwrote:
      On May 24, 2:39 am, Joe Abou Jaoude <anonym...@devd ex.comwrote:
      >
      >
      >
      Hi,
      >
      I want to initialize a number of objects via an xml file, and I was
      wondering if that can be done through a section in the app.config file
      without the need to use another config file.
      >
      example:
      if we have the class:
      Public Class myClass
      >
      Public property prop1
      Public property prop2
      >
      ...
      >
      End Class
      >
      the config file would be something like this:
      <config>
      <MyClass>
      <prop1>abc</prop1>
      <prop2>xyz</prop2>
      </MyClass>
      <MyClass>
      <prop1>deg</prop1>
      <prop2>klm</prop2>
      </MyClass>
      </config>
      >
      is there a way to do that in the app.config file ?
      >
      Thank you
      >
      *** Sent via Developersdexht tp://www.developersd ex.com***
      is there a way to do that in the app.config file ?
      >
      I don't think there is an automatic way of doing this, but you could
      easily write a procedure to grab the values from the app.config file
      and assign them to class's properties. Everything you need should be
      in the System.Xml namespace.
      >
      Thanks,
      >
      Seth Rowe
      You would have to create a class derived from ConfigurationSe ction and
      then add an entry for this class in <ConfigSections element in the
      app.config.

      In code, you could then access your config section with code similar
      to this:

      //SaafProvisionin gSection cfg =
      (SaafProvisioni ngSection)Confi gurationManager .GetSection("Sa afProvisioning" );

      Dim cfg As MyConfigSection =
      DirectCast(Conf igurationManage r.GetSection("M yConfigSection" ),
      MyConfigSection )

      And then access the properties of the class.

      Look up ConfigurationSe ction in the help and it should tell how to
      derive from it.

      Chris

      Comment

      • Chris Dunaway

        #4
        Re: initializing objects via an xml file

        On May 24, 8:23 am, Chris Dunaway <dunaw...@gmail .comwrote:
        On May 24, 5:59 am, rowe_newsgroups <rowe_em...@yah oo.comwrote:
        >
        >
        >
        On May 24, 2:39 am, Joe Abou Jaoude <anonym...@devd ex.comwrote:
        >
        Hi,
        >
        I want to initialize a number of objects via an xml file, and I was
        wondering if that can be done through a section in the app.config file
        without the need to use another config file.
        >
        example:
        if we have the class:
        Public Class myClass
        >
        Public property prop1
        Public property prop2
        >
        ...
        >
        End Class
        >
        the config file would be something like this:
        <config>
        <MyClass>
        <prop1>abc</prop1>
        <prop2>xyz</prop2>
        </MyClass>
        <MyClass>
        <prop1>deg</prop1>
        <prop2>klm</prop2>
        </MyClass>
        </config>
        >
        is there a way to do that in the app.config file ?
        >
        Thank you
        >
        *** Sent via Developersdexht tp://www.developersd ex.com***
        is there a way to do that in the app.config file ?
        >
        I don't think there is an automatic way of doing this, but you could
        easily write a procedure to grab the values from the app.config file
        and assign them to class's properties. Everything you need should be
        in the System.Xml namespace.
        >
        Thanks,
        >
        Seth Rowe
        >
        You would have to create a class derived from ConfigurationSe ction and
        then add an entry for this class in <ConfigSections element in the
        app.config.
        >
        In code, you could then access your config section with code similar
        to this:
        >
        //SaafProvisionin gSection cfg =
        (SaafProvisioni ngSection)Confi gurationManager .GetSection("Sa afProvisioning" );
        >
        Dim cfg As MyConfigSection =
        DirectCast(Conf igurationManage r.GetSection("M yConfigSection" ),
        MyConfigSection )
        >
        And then access the properties of the class.
        >
        Look up ConfigurationSe ction in the help and it should tell how to
        derive from it.
        >
        Chris
        Oops! Ignore commented C# line (the one with SaafProvisionin gSection)
        that is not needed.

        Chris


        Comment

        Working...