Using XML to store global variables in memory

Discussion in 'ASP .Net' started by Davíð Þórisson, Oct 24, 2004.

  1. now in my web I have some global variables to be used in many different
    subpages, in the old ASP I simply loaded a variables.asp file into memory
    using the eval() function. Now I'd like to use XML but what method would I
    use to load the entries from the xml file into memory and make them quickly
    accessible globally in the web code? Just need to know what functions
    specifically I should start reading about!

    Thx
    Davíð Þórisson, Oct 24, 2004
    #1
    1. Advertising

  2. XmlDocument class and its methods (like Load and LoadXML). On the other hand
    I am not sure why Xml? XML is a lot of things, all of them great, but it is
    hardly the best way to keep a bunch of variables. You would be better off
    creating a class, making your variables members(properties) of this class and
    attaching your calss to either Session or Application. I also usually declare
    a static member on the class with the string id which is used to access the
    object of the class from the application collection. This way you are fully
    proteced from typos in you string ids

    HTH, Michael

    "Davíð Þórisson" wrote:

    > now in my web I have some global variables to be used in many different
    > subpages, in the old ASP I simply loaded a variables.asp file into memory
    > using the eval() function. Now I'd like to use XML but what method would I
    > use to load the entries from the xml file into memory and make them quickly
    > accessible globally in the web code? Just need to know what functions
    > specifically I should start reading about!
    >
    > Thx
    >
    >
    >
    =?Utf-8?B?bWZlaW5nb2xk?=, Oct 24, 2004
    #2
    1. Advertising

  3. Thx Michael,
    well you see I have several webs on the same application (using the same
    core but different layouts and urls) so that the variables vary according to
    which web it is. I want to be able to quickly access the web specific
    variables eg
    string Title = Web1.Title ...

    instead of having several titles eg
    string TitleForWeb1
    string TitleForWeb2 ...

    thats the idea!

    "mfeingold" <> wrote in message
    news:...
    > XmlDocument class and its methods (like Load and LoadXML). On the other
    > hand
    > I am not sure why Xml? XML is a lot of things, all of them great, but it
    > is
    > hardly the best way to keep a bunch of variables. You would be better off
    > creating a class, making your variables members(properties) of this class
    > and
    > attaching your calss to either Session or Application. I also usually
    > declare
    > a static member on the class with the string id which is used to access
    > the
    > object of the class from the application collection. This way you are
    > fully
    > proteced from typos in you string ids
    >
    > HTH, Michael
    >
    > "Davíð Þórisson" wrote:
    >
    >> now in my web I have some global variables to be used in many different
    >> subpages, in the old ASP I simply loaded a variables.asp file into memory
    >> using the eval() function. Now I'd like to use XML but what method would
    >> I
    >> use to load the entries from the xml file into memory and make them
    >> quickly
    >> accessible globally in the web code? Just need to know what functions
    >> specifically I should start reading about!
    >>
    >> Thx
    >>
    >>
    >>
    Davíð Þórisson, Oct 24, 2004
    #3
  4. well, with xml you will have to write something like
    MyXmlDoc["Web1"].Attributes["Title"].Value
    assuming that MyXmlDoc is your document looks something like
    <root><Web1 Title="...."/><Web2 Title="..."/></root>
    A lot of coding to what end? still you can mistype atribute name or node
    name and the compiler will not tell you a thing
    on the other hand with the class - you can define methods
    like getTitle, which would take the web name as a parameter, and even throw
    an exception to notify you that the web name is incorrect



    "Davíð Þórisson" wrote:

    > Thx Michael,
    > well you see I have several webs on the same application (using the same
    > core but different layouts and urls) so that the variables vary according to
    > which web it is. I want to be able to quickly access the web specific
    > variables eg
    > string Title = Web1.Title ...
    >
    > instead of having several titles eg
    > string TitleForWeb1
    > string TitleForWeb2 ...
    >
    > thats the idea!
    >
    > "mfeingold" <> wrote in message
    > news:...
    > > XmlDocument class and its methods (like Load and LoadXML). On the other
    > > hand
    > > I am not sure why Xml? XML is a lot of things, all of them great, but it
    > > is
    > > hardly the best way to keep a bunch of variables. You would be better off
    > > creating a class, making your variables members(properties) of this class
    > > and
    > > attaching your calss to either Session or Application. I also usually
    > > declare
    > > a static member on the class with the string id which is used to access
    > > the
    > > object of the class from the application collection. This way you are
    > > fully
    > > proteced from typos in you string ids
    > >
    > > HTH, Michael
    > >
    > > "Davíð Þórisson" wrote:
    > >
    > >> now in my web I have some global variables to be used in many different
    > >> subpages, in the old ASP I simply loaded a variables.asp file into memory
    > >> using the eval() function. Now I'd like to use XML but what method would
    > >> I
    > >> use to load the entries from the xml file into memory and make them
    > >> quickly
    > >> accessible globally in the web code? Just need to know what functions
    > >> specifically I should start reading about!
    > >>
    > >> Thx
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?bWZlaW5nb2xk?=, Oct 24, 2004
    #4
  5. good point Michael, I just cannot grasp the concept of using a Class (=code)
    for storing data (normally stored as strings, dbase entries or as in my ASP
    example as variables in a text file then evaled())...
    I will keep your idea in mind, has some interesting aspects to look into

    "mfeingold" <> wrote in message
    news:...
    > well, with xml you will have to write something like
    > MyXmlDoc["Web1"].Attributes["Title"].Value
    > assuming that MyXmlDoc is your document looks something like
    > <root><Web1 Title="...."/><Web2 Title="..."/></root>
    > A lot of coding to what end? still you can mistype atribute name or node
    > name and the compiler will not tell you a thing
    > on the other hand with the class - you can define methods
    > like getTitle, which would take the web name as a parameter, and even
    > throw
    > an exception to notify you that the web name is incorrect
    >
    >
    >
    > "Davíð Þórisson" wrote:
    >
    >> Thx Michael,
    >> well you see I have several webs on the same application (using the same
    >> core but different layouts and urls) so that the variables vary according
    >> to
    >> which web it is. I want to be able to quickly access the web specific
    >> variables eg
    >> string Title = Web1.Title ...
    >>
    >> instead of having several titles eg
    >> string TitleForWeb1
    >> string TitleForWeb2 ...
    >>
    >> thats the idea!
    >>
    >> "mfeingold" <> wrote in message
    >> news:...
    >> > XmlDocument class and its methods (like Load and LoadXML). On the other
    >> > hand
    >> > I am not sure why Xml? XML is a lot of things, all of them great, but
    >> > it
    >> > is
    >> > hardly the best way to keep a bunch of variables. You would be better
    >> > off
    >> > creating a class, making your variables members(properties) of this
    >> > class
    >> > and
    >> > attaching your calss to either Session or Application. I also usually
    >> > declare
    >> > a static member on the class with the string id which is used to access
    >> > the
    >> > object of the class from the application collection. This way you are
    >> > fully
    >> > proteced from typos in you string ids
    >> >
    >> > HTH, Michael
    >> >
    >> > "Davíð Þórisson" wrote:
    >> >
    >> >> now in my web I have some global variables to be used in many
    >> >> different
    >> >> subpages, in the old ASP I simply loaded a variables.asp file into
    >> >> memory
    >> >> using the eval() function. Now I'd like to use XML but what method
    >> >> would
    >> >> I
    >> >> use to load the entries from the xml file into memory and make them
    >> >> quickly
    >> >> accessible globally in the web code? Just need to know what functions
    >> >> specifically I should start reading about!
    >> >>
    >> >> Thx
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
    Davíð Þórisson, Oct 24, 2004
    #5
  6. Michael, since I'm not so experienced in .Net, how would you construct such
    a class so that you can access the variables eg
    string title = Web1.Title;

    ?


    "Davíð Þórisson" <> wrote in message
    news:...
    > good point Michael, I just cannot grasp the concept of using a Class
    > (=code) for storing data (normally stored as strings, dbase entries or as
    > in my ASP example as variables in a text file then evaled())...
    > I will keep your idea in mind, has some interesting aspects to look into
    >
    > "mfeingold" <> wrote in message
    > news:...
    >> well, with xml you will have to write something like
    >> MyXmlDoc["Web1"].Attributes["Title"].Value
    >> assuming that MyXmlDoc is your document looks something like
    >> <root><Web1 Title="...."/><Web2 Title="..."/></root>
    >> A lot of coding to what end? still you can mistype atribute name or node
    >> name and the compiler will not tell you a thing
    >> on the other hand with the class - you can define methods
    >> like getTitle, which would take the web name as a parameter, and even
    >> throw
    >> an exception to notify you that the web name is incorrect
    >>
    >>
    >>
    >> "Davíð Þórisson" wrote:
    >>
    >>> Thx Michael,
    >>> well you see I have several webs on the same application (using the same
    >>> core but different layouts and urls) so that the variables vary
    >>> according to
    >>> which web it is. I want to be able to quickly access the web specific
    >>> variables eg
    >>> string Title = Web1.Title ...
    >>>
    >>> instead of having several titles eg
    >>> string TitleForWeb1
    >>> string TitleForWeb2 ...
    >>>
    >>> thats the idea!
    >>>
    >>> "mfeingold" <> wrote in message
    >>> news:...
    >>> > XmlDocument class and its methods (like Load and LoadXML). On the
    >>> > other
    >>> > hand
    >>> > I am not sure why Xml? XML is a lot of things, all of them great, but
    >>> > it
    >>> > is
    >>> > hardly the best way to keep a bunch of variables. You would be better
    >>> > off
    >>> > creating a class, making your variables members(properties) of this
    >>> > class
    >>> > and
    >>> > attaching your calss to either Session or Application. I also usually
    >>> > declare
    >>> > a static member on the class with the string id which is used to
    >>> > access
    >>> > the
    >>> > object of the class from the application collection. This way you are
    >>> > fully
    >>> > proteced from typos in you string ids
    >>> >
    >>> > HTH, Michael
    >>> >
    >>> > "Davíð Þórisson" wrote:
    >>> >
    >>> >> now in my web I have some global variables to be used in many
    >>> >> different
    >>> >> subpages, in the old ASP I simply loaded a variables.asp file into
    >>> >> memory
    >>> >> using the eval() function. Now I'd like to use XML but what method
    >>> >> would
    >>> >> I
    >>> >> use to load the entries from the xml file into memory and make them
    >>> >> quickly
    >>> >> accessible globally in the web code? Just need to know what functions
    >>> >> specifically I should start reading about!
    >>> >>
    >>> >> Thx
    >>> >>
    >>> >>
    >>> >>
    >>>
    >>>
    >>>

    >
    >
    Davíð Þórisson, Oct 24, 2004
    #6
  7. One way of doing this would be to create a class and inherit it from
    System.Web.UI.Page somthing like this:

    public class MyPageClass : System.Web.UI.Page
    {

    private string title;
    public string Title {get{return title;}}

    override protected void OnInit(EventArgs e)
    {
    base.OnInit(e);
    title = "......";
    }
    }

    Now, after you created a new page in your project, open its code-behind
    class and change the default base class it inherits from (which will be
    System.Web.UI.Page) to the class you just created. This way the MyPageClass
    will become an ancestor of all your pages, so anywhere in the code both in
    code behind class and imbedded code you will have access to the properties
    and methods you would define in MyPageClass class.
    Keep in mind that a new instance of this class will be created every time
    yor page is generated, so any values kept in the memebers of this class will
    not survive the roundtrip.
    To take care of this you would need another class wich would be instanciated
    in the application start event and attached to the Application (if it is
    application-wide variables). The MyPage class would retrieve this object and
    populate the values.

    The beauty of this approach is that you have all functionality of
    application scope variables easily accessible from any of your pages: to
    access the title from a page all you need to do is to write this.Title or
    just Title. Compiler will check for you both the names and the data types of
    all your variables. And all details of how it is implemented are hidden in a
    single central place.

    "Davíð Þórisson" wrote:

    > Michael, since I'm not so experienced in .Net, how would you construct such
    > a class so that you can access the variables eg
    > string title = Web1.Title;
    >
    > ?
    >
    >
    > "Davíð Þórisson" <> wrote in message
    > news:...
    > > good point Michael, I just cannot grasp the concept of using a Class
    > > (=code) for storing data (normally stored as strings, dbase entries or as
    > > in my ASP example as variables in a text file then evaled())...
    > > I will keep your idea in mind, has some interesting aspects to look into
    > >
    > > "mfeingold" <> wrote in message
    > > news:...
    > >> well, with xml you will have to write something like
    > >> MyXmlDoc["Web1"].Attributes["Title"].Value
    > >> assuming that MyXmlDoc is your document looks something like
    > >> <root><Web1 Title="...."/><Web2 Title="..."/></root>
    > >> A lot of coding to what end? still you can mistype atribute name or node
    > >> name and the compiler will not tell you a thing
    > >> on the other hand with the class - you can define methods
    > >> like getTitle, which would take the web name as a parameter, and even
    > >> throw
    > >> an exception to notify you that the web name is incorrect
    > >>
    > >>
    > >>
    > >> "Davíð Þórisson" wrote:
    > >>
    > >>> Thx Michael,
    > >>> well you see I have several webs on the same application (using the same
    > >>> core but different layouts and urls) so that the variables vary
    > >>> according to
    > >>> which web it is. I want to be able to quickly access the web specific
    > >>> variables eg
    > >>> string Title = Web1.Title ...
    > >>>
    > >>> instead of having several titles eg
    > >>> string TitleForWeb1
    > >>> string TitleForWeb2 ...
    > >>>
    > >>> thats the idea!
    > >>>
    > >>> "mfeingold" <> wrote in message
    > >>> news:...
    > >>> > XmlDocument class and its methods (like Load and LoadXML). On the
    > >>> > other
    > >>> > hand
    > >>> > I am not sure why Xml? XML is a lot of things, all of them great, but
    > >>> > it
    > >>> > is
    > >>> > hardly the best way to keep a bunch of variables. You would be better
    > >>> > off
    > >>> > creating a class, making your variables members(properties) of this
    > >>> > class
    > >>> > and
    > >>> > attaching your calss to either Session or Application. I also usually
    > >>> > declare
    > >>> > a static member on the class with the string id which is used to
    > >>> > access
    > >>> > the
    > >>> > object of the class from the application collection. This way you are
    > >>> > fully
    > >>> > proteced from typos in you string ids
    > >>> >
    > >>> > HTH, Michael
    > >>> >
    > >>> > "Davíð Þórisson" wrote:
    > >>> >
    > >>> >> now in my web I have some global variables to be used in many
    > >>> >> different
    > >>> >> subpages, in the old ASP I simply loaded a variables.asp file into
    > >>> >> memory
    > >>> >> using the eval() function. Now I'd like to use XML but what method
    > >>> >> would
    > >>> >> I
    > >>> >> use to load the entries from the xml file into memory and make them
    > >>> >> quickly
    > >>> >> accessible globally in the web code? Just need to know what functions
    > >>> >> specifically I should start reading about!
    > >>> >>
    > >>> >> Thx
    > >>> >>
    > >>> >>
    > >>> >>
    > >>>
    > >>>
    > >>>

    > >
    > >

    >
    >
    >
    =?Utf-8?B?bWZlaW5nb2xk?=, Oct 25, 2004
    #7
  8. Hang on a second, David. XML is great stuff, but it isn't the end-all and
    be-all of programming. You stated that you have some "global variables to be
    used in many different subpages." I would guess that means in-memory
    objects. Now, XML is a great tool for passing data around in a distributed
    application, as it is non-proprietry, and can be understood by any XML
    client. But which of the following uses less memory space and processing in
    your application:

    Binary: 32767 (16 bits)

    XML:

    <data name="$this.TrayHeight" type="System.Int32, mscorlib,
    Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <value>32767</value>
    </data>

    IOW, XML is great for what its great for, and lousy for what it's lousy for.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    I get paid good money to
    solve puzzles for a living

    "Davíð Þórisson" <> wrote in message
    news:...
    > now in my web I have some global variables to be used in many different
    > subpages, in the old ASP I simply loaded a variables.asp file into memory
    > using the eval() function. Now I'd like to use XML but what method would I
    > use to load the entries from the xml file into memory and make them

    quickly
    > accessible globally in the web code? Just need to know what functions
    > specifically I should start reading about!
    >
    > Thx
    >
    >
    Kevin Spencer, Oct 25, 2004
    #8
  9. My apologies, David.

    After re-reading your question and my response, I can see that I was not
    answering the question you asked, which is how to read data stored in an XML
    file INTO memory, which is something altogether different from storing XML
    data IN memory. Reading it from a file is a great idea, as exemplified by
    the use of XML for the web.config and other configuration files that ASP.Net
    and .Net in general uses.

    In fact, using the web.config file might be your best bet to begin with. You
    can easily use the built-in "appSettings" element in the web.config to
    define your own data, which can easily be read from the file at run time.
    Example:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appSettings>
    <add key="ConnectionString"
    value="server=blah;uid=Blah;pwd=blahblah;database=blah"/>
    <add key="VoyagerPath" value="C:\VoyagerOnline" />
    <add key="Timeout" value="15" />
    </appSettings>
    ....

    These configuration elements are easy to fetch at run-time. Example:

    Dim Timeout As int =
    System.Configuration.ConfigurationSettings.AppSettings("Timeout")

    You can also define custom configuration sections, if you have a lot of data
    and need to organize it into a nice tree hierarchy.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    I get paid good money to
    solve puzzles for a living

    "Davíð Þórisson" <> wrote in message
    news:...
    > now in my web I have some global variables to be used in many different
    > subpages, in the old ASP I simply loaded a variables.asp file into memory
    > using the eval() function. Now I'd like to use XML but what method would I
    > use to load the entries from the xml file into memory and make them

    quickly
    > accessible globally in the web code? Just need to know what functions
    > specifically I should start reading about!
    >
    > Thx
    >
    >
    Kevin Spencer, Oct 25, 2004
    #9
  10. exactly Kevin, sounds exactly like I need and want to do... so simple and
    elegant solution - thx!


    "Kevin Spencer" <> wrote in message
    news:...
    > My apologies, David.
    >
    > After re-reading your question and my response, I can see that I was not
    > answering the question you asked, which is how to read data stored in an
    > XML
    > file INTO memory, which is something altogether different from storing XML
    > data IN memory. Reading it from a file is a great idea, as exemplified by
    > the use of XML for the web.config and other configuration files that
    > ASP.Net
    > and .Net in general uses.
    >
    > In fact, using the web.config file might be your best bet to begin with.
    > You
    > can easily use the built-in "appSettings" element in the web.config to
    > define your own data, which can easily be read from the file at run time.
    > Example:
    >
    > <?xml version="1.0" encoding="utf-8" ?>
    > <configuration>
    > <appSettings>
    > <add key="ConnectionString"
    > value="server=blah;uid=Blah;pwd=blahblah;database=blah"/>
    > <add key="VoyagerPath" value="C:\VoyagerOnline" />
    > <add key="Timeout" value="15" />
    > </appSettings>
    > ...
    >
    > These configuration elements are easy to fetch at run-time. Example:
    >
    > Dim Timeout As int =
    > System.Configuration.ConfigurationSettings.AppSettings("Timeout")
    >
    > You can also define custom configuration sections, if you have a lot of
    > data
    > and need to organize it into a nice tree hierarchy.
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > I get paid good money to
    > solve puzzles for a living
    >
    > "Davíð Þórisson" <> wrote in message
    > news:...
    >> now in my web I have some global variables to be used in many different
    >> subpages, in the old ASP I simply loaded a variables.asp file into memory
    >> using the eval() function. Now I'd like to use XML but what method would
    >> I
    >> use to load the entries from the xml file into memory and make them

    > quickly
    >> accessible globally in the web code? Just need to know what functions
    >> specifically I should start reading about!
    >>
    >> Thx
    >>
    >>

    >
    >
    Davíð Þórisson, Oct 25, 2004
    #10
  11. Kevin, so far so good but .Net doesn't allow me to split the appsettings
    into subgroups eg
    <appSettings>
    <Web1Group>
    <add key="Title" value="Title of web 1"/>
    ...
    </Web1Group>
    <Web2Group>
    <add key="Title" value="Title of web 2"/>
    ...
    </Web2Group>
    </appSettings>

    The error I get: "Unrecognized element."



    "Kevin Spencer" <> wrote in message
    news:...
    > My apologies, David.
    >
    > After re-reading your question and my response, I can see that I was not
    > answering the question you asked, which is how to read data stored in an
    > XML
    > file INTO memory, which is something altogether different from storing XML
    > data IN memory. Reading it from a file is a great idea, as exemplified by
    > the use of XML for the web.config and other configuration files that
    > ASP.Net
    > and .Net in general uses.
    >
    > In fact, using the web.config file might be your best bet to begin with.
    > You
    > can easily use the built-in "appSettings" element in the web.config to
    > define your own data, which can easily be read from the file at run time.
    > Example:
    >
    > <?xml version="1.0" encoding="utf-8" ?>
    > <configuration>
    > <appSettings>
    > <add key="ConnectionString"
    > value="server=blah;uid=Blah;pwd=blahblah;database=blah"/>
    > <add key="VoyagerPath" value="C:\VoyagerOnline" />
    > <add key="Timeout" value="15" />
    > </appSettings>
    > ...
    >
    > These configuration elements are easy to fetch at run-time. Example:
    >
    > Dim Timeout As int =
    > System.Configuration.ConfigurationSettings.AppSettings("Timeout")
    >
    > You can also define custom configuration sections, if you have a lot of
    > data
    > and need to organize it into a nice tree hierarchy.
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > I get paid good money to
    > solve puzzles for a living
    >
    > "Davíð Þórisson" <> wrote in message
    > news:...
    >> now in my web I have some global variables to be used in many different
    >> subpages, in the old ASP I simply loaded a variables.asp file into memory
    >> using the eval() function. Now I'd like to use XML but what method would
    >> I
    >> use to load the entries from the xml file into memory and make them

    > quickly
    >> accessible globally in the web code? Just need to know what functions
    >> specifically I should start reading about!
    >>
    >> Thx
    >>
    >>

    >
    >
    Davíð Þórisson, Oct 25, 2004
    #11
  12. Correct. Remember I mentioned that you can create your own customized
    Sections? That's what you need here. See the following SDK article for more
    information about how:

    http://msdn.microsoft.com/library/d.../cpguide/html/cpcondeclaringsectiongroups.asp

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    I get paid good money to
    solve puzzles for a living

    "Davíð Þórisson" <> wrote in message
    news:...
    > Kevin, so far so good but .Net doesn't allow me to split the appsettings
    > into subgroups eg
    > <appSettings>
    > <Web1Group>
    > <add key="Title" value="Title of web 1"/>
    > ...
    > </Web1Group>
    > <Web2Group>
    > <add key="Title" value="Title of web 2"/>
    > ...
    > </Web2Group>
    > </appSettings>
    >
    > The error I get: "Unrecognized element."
    >
    >
    >
    > "Kevin Spencer" <> wrote in message
    > news:...
    > > My apologies, David.
    > >
    > > After re-reading your question and my response, I can see that I was not
    > > answering the question you asked, which is how to read data stored in an
    > > XML
    > > file INTO memory, which is something altogether different from storing

    XML
    > > data IN memory. Reading it from a file is a great idea, as exemplified

    by
    > > the use of XML for the web.config and other configuration files that
    > > ASP.Net
    > > and .Net in general uses.
    > >
    > > In fact, using the web.config file might be your best bet to begin with.
    > > You
    > > can easily use the built-in "appSettings" element in the web.config to
    > > define your own data, which can easily be read from the file at run

    time.
    > > Example:
    > >
    > > <?xml version="1.0" encoding="utf-8" ?>
    > > <configuration>
    > > <appSettings>
    > > <add key="ConnectionString"
    > > value="server=blah;uid=Blah;pwd=blahblah;database=blah"/>
    > > <add key="VoyagerPath" value="C:\VoyagerOnline" />
    > > <add key="Timeout" value="15" />
    > > </appSettings>
    > > ...
    > >
    > > These configuration elements are easy to fetch at run-time. Example:
    > >
    > > Dim Timeout As int =
    > > System.Configuration.ConfigurationSettings.AppSettings("Timeout")
    > >
    > > You can also define custom configuration sections, if you have a lot of
    > > data
    > > and need to organize it into a nice tree hierarchy.
    > >
    > > --
    > > HTH,
    > > Kevin Spencer
    > > .Net Developer
    > > Microsoft MVP
    > > I get paid good money to
    > > solve puzzles for a living
    > >
    > > "Davíð Þórisson" <> wrote in message
    > > news:...
    > >> now in my web I have some global variables to be used in many different
    > >> subpages, in the old ASP I simply loaded a variables.asp file into

    memory
    > >> using the eval() function. Now I'd like to use XML but what method

    would
    > >> I
    > >> use to load the entries from the xml file into memory and make them

    > > quickly
    > >> accessible globally in the web code? Just need to know what functions
    > >> specifically I should start reading about!
    > >>
    > >> Thx
    > >>
    > >>

    > >
    > >

    >
    >
    Kevin Spencer, Oct 25, 2004
    #12
  13. I have to admit this is far beyond my knowledge so I just try to copy &
    paste with some common sense... so far I've got the xml file correct but

    NameValueCollection sampleConfig =
    (NameValueCollection)ConfigurationSettings.GetConfig("mySectionGroup/myWeb1");
    string strKeyValue = (string)sampleConfig["Title"];
    myLabel.Text = myVar;

    just brings on an error (surprise): "The type or namespace name
    'NameValueCollection' could not be found (are you missing a using directive
    or an assembly reference?)"


    "Kevin Spencer" <> wrote in message
    news:%...
    > Correct. Remember I mentioned that you can create your own customized
    > Sections? That's what you need here. See the following SDK article for
    > more
    > information about how:
    >
    > http://msdn.microsoft.com/library/d.../cpguide/html/cpcondeclaringsectiongroups.asp
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > I get paid good money to
    > solve puzzles for a living
    >
    > "Davíð Þórisson" <> wrote in message
    > news:...
    >> Kevin, so far so good but .Net doesn't allow me to split the appsettings
    >> into subgroups eg
    >> <appSettings>
    >> <Web1Group>
    >> <add key="Title" value="Title of web 1"/>
    >> ...
    >> </Web1Group>
    >> <Web2Group>
    >> <add key="Title" value="Title of web 2"/>
    >> ...
    >> </Web2Group>
    >> </appSettings>
    >>
    >> The error I get: "Unrecognized element."
    >>
    >>
    >>
    >> "Kevin Spencer" <> wrote in message
    >> news:...
    >> > My apologies, David.
    >> >
    >> > After re-reading your question and my response, I can see that I was
    >> > not
    >> > answering the question you asked, which is how to read data stored in
    >> > an
    >> > XML
    >> > file INTO memory, which is something altogether different from storing

    > XML
    >> > data IN memory. Reading it from a file is a great idea, as exemplified

    > by
    >> > the use of XML for the web.config and other configuration files that
    >> > ASP.Net
    >> > and .Net in general uses.
    >> >
    >> > In fact, using the web.config file might be your best bet to begin
    >> > with.
    >> > You
    >> > can easily use the built-in "appSettings" element in the web.config to
    >> > define your own data, which can easily be read from the file at run

    > time.
    >> > Example:
    >> >
    >> > <?xml version="1.0" encoding="utf-8" ?>
    >> > <configuration>
    >> > <appSettings>
    >> > <add key="ConnectionString"
    >> > value="server=blah;uid=Blah;pwd=blahblah;database=blah"/>
    >> > <add key="VoyagerPath" value="C:\VoyagerOnline" />
    >> > <add key="Timeout" value="15" />
    >> > </appSettings>
    >> > ...
    >> >
    >> > These configuration elements are easy to fetch at run-time. Example:
    >> >
    >> > Dim Timeout As int =
    >> > System.Configuration.ConfigurationSettings.AppSettings("Timeout")
    >> >
    >> > You can also define custom configuration sections, if you have a lot of
    >> > data
    >> > and need to organize it into a nice tree hierarchy.
    >> >
    >> > --
    >> > HTH,
    >> > Kevin Spencer
    >> > .Net Developer
    >> > Microsoft MVP
    >> > I get paid good money to
    >> > solve puzzles for a living
    >> >
    >> > "Davíð Þórisson" <> wrote in message
    >> > news:...
    >> >> now in my web I have some global variables to be used in many
    >> >> different
    >> >> subpages, in the old ASP I simply loaded a variables.asp file into

    > memory
    >> >> using the eval() function. Now I'd like to use XML but what method

    > would
    >> >> I
    >> >> use to load the entries from the xml file into memory and make them
    >> > quickly
    >> >> accessible globally in the web code? Just need to know what functions
    >> >> specifically I should start reading about!
    >> >>
    >> >> Thx
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
    Davíð Þórisson, Oct 25, 2004
    #13
  14. If the type cannot be found, one or both of 2 things is happening. Either
    you haven't referenced the assembly (DLL), or you haven't added a using
    statement to negate the necessity of using the complete NameSpace hierarchy
    in your code. The complete NameSpace for NameValueCollection is
    "System.Collections.Specialized.NameValueCollection".

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    I get paid good money to
    solve puzzles for a living


    "Davíð Þórisson" <> wrote in message
    news:#...
    > I have to admit this is far beyond my knowledge so I just try to copy &
    > paste with some common sense... so far I've got the xml file correct but
    >
    > NameValueCollection sampleConfig =
    >

    (NameValueCollection)ConfigurationSettings.GetConfig("mySectionGroup/myWeb1"
    );
    > string strKeyValue = (string)sampleConfig["Title"];
    > myLabel.Text = myVar;
    >
    > just brings on an error (surprise): "The type or namespace name
    > 'NameValueCollection' could not be found (are you missing a using

    directive
    > or an assembly reference?)"
    >
    >
    > "Kevin Spencer" <> wrote in message
    > news:%...
    > > Correct. Remember I mentioned that you can create your own customized
    > > Sections? That's what you need here. See the following SDK article for
    > > more
    > > information about how:
    > >
    > >

    http://msdn.microsoft.com/library/d.../cpguide/html/cpcondeclaringsectiongroups.asp
    > >
    > > --
    > > HTH,
    > > Kevin Spencer
    > > .Net Developer
    > > Microsoft MVP
    > > I get paid good money to
    > > solve puzzles for a living
    > >
    > > "Davíð Þórisson" <> wrote in message
    > > news:...
    > >> Kevin, so far so good but .Net doesn't allow me to split the

    appsettings
    > >> into subgroups eg
    > >> <appSettings>
    > >> <Web1Group>
    > >> <add key="Title" value="Title of web 1"/>
    > >> ...
    > >> </Web1Group>
    > >> <Web2Group>
    > >> <add key="Title" value="Title of web 2"/>
    > >> ...
    > >> </Web2Group>
    > >> </appSettings>
    > >>
    > >> The error I get: "Unrecognized element."
    > >>
    > >>
    > >>
    > >> "Kevin Spencer" <> wrote in message
    > >> news:...
    > >> > My apologies, David.
    > >> >
    > >> > After re-reading your question and my response, I can see that I was
    > >> > not
    > >> > answering the question you asked, which is how to read data stored in
    > >> > an
    > >> > XML
    > >> > file INTO memory, which is something altogether different from

    storing
    > > XML
    > >> > data IN memory. Reading it from a file is a great idea, as

    exemplified
    > > by
    > >> > the use of XML for the web.config and other configuration files that
    > >> > ASP.Net
    > >> > and .Net in general uses.
    > >> >
    > >> > In fact, using the web.config file might be your best bet to begin
    > >> > with.
    > >> > You
    > >> > can easily use the built-in "appSettings" element in the web.config

    to
    > >> > define your own data, which can easily be read from the file at run

    > > time.
    > >> > Example:
    > >> >
    > >> > <?xml version="1.0" encoding="utf-8" ?>
    > >> > <configuration>
    > >> > <appSettings>
    > >> > <add key="ConnectionString"
    > >> > value="server=blah;uid=Blah;pwd=blahblah;database=blah"/>
    > >> > <add key="VoyagerPath" value="C:\VoyagerOnline" />
    > >> > <add key="Timeout" value="15" />
    > >> > </appSettings>
    > >> > ...
    > >> >
    > >> > These configuration elements are easy to fetch at run-time. Example:
    > >> >
    > >> > Dim Timeout As int =
    > >> > System.Configuration.ConfigurationSettings.AppSettings("Timeout")
    > >> >
    > >> > You can also define custom configuration sections, if you have a lot

    of
    > >> > data
    > >> > and need to organize it into a nice tree hierarchy.
    > >> >
    > >> > --
    > >> > HTH,
    > >> > Kevin Spencer
    > >> > .Net Developer
    > >> > Microsoft MVP
    > >> > I get paid good money to
    > >> > solve puzzles for a living
    > >> >
    > >> > "Davíð Þórisson" <> wrote in message
    > >> > news:...
    > >> >> now in my web I have some global variables to be used in many
    > >> >> different
    > >> >> subpages, in the old ASP I simply loaded a variables.asp file into

    > > memory
    > >> >> using the eval() function. Now I'd like to use XML but what method

    > > would
    > >> >> I
    > >> >> use to load the entries from the xml file into memory and make them
    > >> > quickly
    > >> >> accessible globally in the web code? Just need to know what

    functions
    > >> >> specifically I should start reading about!
    > >> >>
    > >> >> Thx
    > >> >>
    > >> >>
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
    Kevin Spencer, Oct 26, 2004
    #14
  15. Kevin
    could you kindly email me, I'm so close to getting this done (the using
    statement is there) still some error I can't figure out :(


    "Kevin Spencer" <> wrote in message
    news:...
    > If the type cannot be found, one or both of 2 things is happening. Either
    > you haven't referenced the assembly (DLL), or you haven't added a using
    > statement to negate the necessity of using the complete NameSpace
    > hierarchy
    > in your code. The complete NameSpace for NameValueCollection is
    > "System.Collections.Specialized.NameValueCollection".
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > I get paid good money to
    > solve puzzles for a living
    >
    >
    > "Davíð Þórisson" <> wrote in message
    > news:#...
    >> I have to admit this is far beyond my knowledge so I just try to copy &
    >> paste with some common sense... so far I've got the xml file correct but
    >>
    >> NameValueCollection sampleConfig =
    >>

    > (NameValueCollection)ConfigurationSettings.GetConfig("mySectionGroup/myWeb1"
    > );
    >> string strKeyValue = (string)sampleConfig["Title"];
    >> myLabel.Text = myVar;
    >>
    >> just brings on an error (surprise): "The type or namespace name
    >> 'NameValueCollection' could not be found (are you missing a using

    > directive
    >> or an assembly reference?)"
    >>
    >>
    >> "Kevin Spencer" <> wrote in message
    >> news:%...
    >> > Correct. Remember I mentioned that you can create your own customized
    >> > Sections? That's what you need here. See the following SDK article for
    >> > more
    >> > information about how:
    >> >
    >> >

    > http://msdn.microsoft.com/library/d.../cpguide/html/cpcondeclaringsectiongroups.asp
    >> >
    >> > --
    >> > HTH,
    >> > Kevin Spencer
    >> > .Net Developer
    >> > Microsoft MVP
    >> > I get paid good money to
    >> > solve puzzles for a living
    >> >
    >> > "Davíð Þórisson" <> wrote in message
    >> > news:...
    >> >> Kevin, so far so good but .Net doesn't allow me to split the

    > appsettings
    >> >> into subgroups eg
    >> >> <appSettings>
    >> >> <Web1Group>
    >> >> <add key="Title" value="Title of web 1"/>
    >> >> ...
    >> >> </Web1Group>
    >> >> <Web2Group>
    >> >> <add key="Title" value="Title of web 2"/>
    >> >> ...
    >> >> </Web2Group>
    >> >> </appSettings>
    >> >>
    >> >> The error I get: "Unrecognized element."
    >> >>
    >> >>
    >> >>
    >> >> "Kevin Spencer" <> wrote in message
    >> >> news:...
    >> >> > My apologies, David.
    >> >> >
    >> >> > After re-reading your question and my response, I can see that I was
    >> >> > not
    >> >> > answering the question you asked, which is how to read data stored
    >> >> > in
    >> >> > an
    >> >> > XML
    >> >> > file INTO memory, which is something altogether different from

    > storing
    >> > XML
    >> >> > data IN memory. Reading it from a file is a great idea, as

    > exemplified
    >> > by
    >> >> > the use of XML for the web.config and other configuration files that
    >> >> > ASP.Net
    >> >> > and .Net in general uses.
    >> >> >
    >> >> > In fact, using the web.config file might be your best bet to begin
    >> >> > with.
    >> >> > You
    >> >> > can easily use the built-in "appSettings" element in the web.config

    > to
    >> >> > define your own data, which can easily be read from the file at run
    >> > time.
    >> >> > Example:
    >> >> >
    >> >> > <?xml version="1.0" encoding="utf-8" ?>
    >> >> > <configuration>
    >> >> > <appSettings>
    >> >> > <add key="ConnectionString"
    >> >> > value="server=blah;uid=Blah;pwd=blahblah;database=blah"/>
    >> >> > <add key="VoyagerPath" value="C:\VoyagerOnline" />
    >> >> > <add key="Timeout" value="15" />
    >> >> > </appSettings>
    >> >> > ...
    >> >> >
    >> >> > These configuration elements are easy to fetch at run-time. Example:
    >> >> >
    >> >> > Dim Timeout As int =
    >> >> > System.Configuration.ConfigurationSettings.AppSettings("Timeout")
    >> >> >
    >> >> > You can also define custom configuration sections, if you have a lot

    > of
    >> >> > data
    >> >> > and need to organize it into a nice tree hierarchy.
    >> >> >
    >> >> > --
    >> >> > HTH,
    >> >> > Kevin Spencer
    >> >> > .Net Developer
    >> >> > Microsoft MVP
    >> >> > I get paid good money to
    >> >> > solve puzzles for a living
    >> >> >
    >> >> > "Davíð Þórisson" <> wrote in message
    >> >> > news:...
    >> >> >> now in my web I have some global variables to be used in many
    >> >> >> different
    >> >> >> subpages, in the old ASP I simply loaded a variables.asp file into
    >> > memory
    >> >> >> using the eval() function. Now I'd like to use XML but what method
    >> > would
    >> >> >> I
    >> >> >> use to load the entries from the xml file into memory and make them
    >> >> > quickly
    >> >> >> accessible globally in the web code? Just need to know what

    > functions
    >> >> >> specifically I should start reading about!
    >> >> >>
    >> >> >> Thx
    >> >> >>
    >> >> >>
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
    Davíð Þórisson, Oct 26, 2004
    #15
  16. Hi David,

    I'm afraid I don't help people by email, for a number of reasons too long to
    go into here.

    I will be happy to continue helping you on this newsgroup, however, if you
    can tell me where you're having trouble. the article (and related articles)
    should give you what you need to know. The section head for the article I
    pointed you to is at:

    http://msdn.microsoft.com/library/e...onconfigurationsectionhandlers.asp?frame=true

    but I can also answer any specific questions you may have.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    I get paid good money to
    solve puzzles for a living

    "Davíð Þórisson" <> wrote in message
    news:...
    > Kevin
    > could you kindly email me, I'm so close to getting this done (the using
    > statement is there) still some error I can't figure out :(
    >
    >
    > "Kevin Spencer" <> wrote in message
    > news:...
    > > If the type cannot be found, one or both of 2 things is happening.

    Either
    > > you haven't referenced the assembly (DLL), or you haven't added a using
    > > statement to negate the necessity of using the complete NameSpace
    > > hierarchy
    > > in your code. The complete NameSpace for NameValueCollection is
    > > "System.Collections.Specialized.NameValueCollection".
    > >
    > > --
    > > HTH,
    > > Kevin Spencer
    > > .Net Developer
    > > Microsoft MVP
    > > I get paid good money to
    > > solve puzzles for a living
    > >
    > >
    > > "Davíð Þórisson" <> wrote in message
    > > news:#...
    > >> I have to admit this is far beyond my knowledge so I just try to copy &
    > >> paste with some common sense... so far I've got the xml file correct

    but
    > >>
    > >> NameValueCollection sampleConfig =
    > >>

    > >

    (NameValueCollection)ConfigurationSettings.GetConfig("mySectionGroup/myWeb1"
    > > );
    > >> string strKeyValue = (string)sampleConfig["Title"];
    > >> myLabel.Text = myVar;
    > >>
    > >> just brings on an error (surprise): "The type or namespace name
    > >> 'NameValueCollection' could not be found (are you missing a using

    > > directive
    > >> or an assembly reference?)"
    > >>
    > >>
    > >> "Kevin Spencer" <> wrote in message
    > >> news:%...
    > >> > Correct. Remember I mentioned that you can create your own customized
    > >> > Sections? That's what you need here. See the following SDK article

    for
    > >> > more
    > >> > information about how:
    > >> >
    > >> >

    > >

    http://msdn.microsoft.com/library/d.../cpguide/html/cpcondeclaringsectiongroups.asp
    > >> >
    > >> > --
    > >> > HTH,
    > >> > Kevin Spencer
    > >> > .Net Developer
    > >> > Microsoft MVP
    > >> > I get paid good money to
    > >> > solve puzzles for a living
    > >> >
    > >> > "Davíð Þórisson" <> wrote in message
    > >> > news:...
    > >> >> Kevin, so far so good but .Net doesn't allow me to split the

    > > appsettings
    > >> >> into subgroups eg
    > >> >> <appSettings>
    > >> >> <Web1Group>
    > >> >> <add key="Title" value="Title of web 1"/>
    > >> >> ...
    > >> >> </Web1Group>
    > >> >> <Web2Group>
    > >> >> <add key="Title" value="Title of web 2"/>
    > >> >> ...
    > >> >> </Web2Group>
    > >> >> </appSettings>
    > >> >>
    > >> >> The error I get: "Unrecognized element."
    > >> >>
    > >> >>
    > >> >>
    > >> >> "Kevin Spencer" <> wrote in message
    > >> >> news:...
    > >> >> > My apologies, David.
    > >> >> >
    > >> >> > After re-reading your question and my response, I can see that I

    was
    > >> >> > not
    > >> >> > answering the question you asked, which is how to read data stored
    > >> >> > in
    > >> >> > an
    > >> >> > XML
    > >> >> > file INTO memory, which is something altogether different from

    > > storing
    > >> > XML
    > >> >> > data IN memory. Reading it from a file is a great idea, as

    > > exemplified
    > >> > by
    > >> >> > the use of XML for the web.config and other configuration files

    that
    > >> >> > ASP.Net
    > >> >> > and .Net in general uses.
    > >> >> >
    > >> >> > In fact, using the web.config file might be your best bet to begin
    > >> >> > with.
    > >> >> > You
    > >> >> > can easily use the built-in "appSettings" element in the

    web.config
    > > to
    > >> >> > define your own data, which can easily be read from the file at

    run
    > >> > time.
    > >> >> > Example:
    > >> >> >
    > >> >> > <?xml version="1.0" encoding="utf-8" ?>
    > >> >> > <configuration>
    > >> >> > <appSettings>
    > >> >> > <add key="ConnectionString"
    > >> >> > value="server=blah;uid=Blah;pwd=blahblah;database=blah"/>
    > >> >> > <add key="VoyagerPath" value="C:\VoyagerOnline" />
    > >> >> > <add key="Timeout" value="15" />
    > >> >> > </appSettings>
    > >> >> > ...
    > >> >> >
    > >> >> > These configuration elements are easy to fetch at run-time.

    Example:
    > >> >> >
    > >> >> > Dim Timeout As int =
    > >> >> > System.Configuration.ConfigurationSettings.AppSettings("Timeout")
    > >> >> >
    > >> >> > You can also define custom configuration sections, if you have a

    lot
    > > of
    > >> >> > data
    > >> >> > and need to organize it into a nice tree hierarchy.
    > >> >> >
    > >> >> > --
    > >> >> > HTH,
    > >> >> > Kevin Spencer
    > >> >> > .Net Developer
    > >> >> > Microsoft MVP
    > >> >> > I get paid good money to
    > >> >> > solve puzzles for a living
    > >> >> >
    > >> >> > "Davíð Þórisson" <> wrote in message
    > >> >> > news:...
    > >> >> >> now in my web I have some global variables to be used in many
    > >> >> >> different
    > >> >> >> subpages, in the old ASP I simply loaded a variables.asp file

    into
    > >> > memory
    > >> >> >> using the eval() function. Now I'd like to use XML but what

    method
    > >> > would
    > >> >> >> I
    > >> >> >> use to load the entries from the xml file into memory and make

    them
    > >> >> > quickly
    > >> >> >> accessible globally in the web code? Just need to know what

    > > functions
    > >> >> >> specifically I should start reading about!
    > >> >> >>
    > >> >> >> Thx
    > >> >> >>
    > >> >> >>
    > >> >> >
    > >> >> >
    > >> >>
    > >> >>
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
    Kevin Spencer, Oct 26, 2004
    #16
  17. no prob Kevin, I understand.
    After some Googling I finally managed to solve this although I don't know at
    all why. What I did was changing:
    <section name="mySection"
    type="System.Configuration.NameValueSectionHandler,System/>
    to:
    <section name="mySection"
    type="System.Configuration.NameValueSectionHandler,System,
    Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089,
    Custom=null" />

    god knows what that Version bla bla does but it works!!! (I always thought
    XML was sooo easy and clean code)

    "Kevin Spencer" <> wrote in message
    news:...
    > Hi David,
    >
    > I'm afraid I don't help people by email, for a number of reasons too long
    > to
    > go into here.
    >
    > I will be happy to continue helping you on this newsgroup, however, if
    > you
    > can tell me where you're having trouble. the article (and related
    > articles)
    > should give you what you need to know. The section head for the article I
    > pointed you to is at:
    >
    > http://msdn.microsoft.com/library/e...onconfigurationsectionhandlers.asp?frame=true
    >
    > but I can also answer any specific questions you may have.
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > I get paid good money to
    > solve puzzles for a living
    >
    > "Davíð Þórisson" <> wrote in message
    > news:...
    >> Kevin
    >> could you kindly email me, I'm so close to getting this done (the using
    >> statement is there) still some error I can't figure out :(
    >>
    >>
    >> "Kevin Spencer" <> wrote in message
    >> news:...
    >> > If the type cannot be found, one or both of 2 things is happening.

    > Either
    >> > you haven't referenced the assembly (DLL), or you haven't added a using
    >> > statement to negate the necessity of using the complete NameSpace
    >> > hierarchy
    >> > in your code. The complete NameSpace for NameValueCollection is
    >> > "System.Collections.Specialized.NameValueCollection".
    >> >
    >> > --
    >> > HTH,
    >> > Kevin Spencer
    >> > .Net Developer
    >> > Microsoft MVP
    >> > I get paid good money to
    >> > solve puzzles for a living
    >> >
    >> >
    >> > "Davíð Þórisson" <> wrote in message
    >> > news:#...
    >> >> I have to admit this is far beyond my knowledge so I just try to copy
    >> >> &
    >> >> paste with some common sense... so far I've got the xml file correct

    > but
    >> >>
    >> >> NameValueCollection sampleConfig =
    >> >>
    >> >

    > (NameValueCollection)ConfigurationSettings.GetConfig("mySectionGroup/myWeb1"
    >> > );
    >> >> string strKeyValue = (string)sampleConfig["Title"];
    >> >> myLabel.Text = myVar;
    >> >>
    >> >> just brings on an error (surprise): "The type or namespace name
    >> >> 'NameValueCollection' could not be found (are you missing a using
    >> > directive
    >> >> or an assembly reference?)"
    >> >>
    >> >>
    >> >> "Kevin Spencer" <> wrote in message
    >> >> news:%...
    >> >> > Correct. Remember I mentioned that you can create your own
    >> >> > customized
    >> >> > Sections? That's what you need here. See the following SDK article

    > for
    >> >> > more
    >> >> > information about how:
    >> >> >
    >> >> >
    >> >

    > http://msdn.microsoft.com/library/d.../cpguide/html/cpcondeclaringsectiongroups.asp
    >> >> >
    >> >> > --
    >> >> > HTH,
    >> >> > Kevin Spencer
    >> >> > .Net Developer
    >> >> > Microsoft MVP
    >> >> > I get paid good money to
    >> >> > solve puzzles for a living
    >> >> >
    >> >> > "Davíð Þórisson" <> wrote in message
    >> >> > news:...
    >> >> >> Kevin, so far so good but .Net doesn't allow me to split the
    >> > appsettings
    >> >> >> into subgroups eg
    >> >> >> <appSettings>
    >> >> >> <Web1Group>
    >> >> >> <add key="Title" value="Title of web 1"/>
    >> >> >> ...
    >> >> >> </Web1Group>
    >> >> >> <Web2Group>
    >> >> >> <add key="Title" value="Title of web 2"/>
    >> >> >> ...
    >> >> >> </Web2Group>
    >> >> >> </appSettings>
    >> >> >>
    >> >> >> The error I get: "Unrecognized element."
    >> >> >>
    >> >> >>
    >> >> >>
    >> >> >> "Kevin Spencer" <> wrote in message
    >> >> >> news:...
    >> >> >> > My apologies, David.
    >> >> >> >
    >> >> >> > After re-reading your question and my response, I can see that I

    > was
    >> >> >> > not
    >> >> >> > answering the question you asked, which is how to read data
    >> >> >> > stored
    >> >> >> > in
    >> >> >> > an
    >> >> >> > XML
    >> >> >> > file INTO memory, which is something altogether different from
    >> > storing
    >> >> > XML
    >> >> >> > data IN memory. Reading it from a file is a great idea, as
    >> > exemplified
    >> >> > by
    >> >> >> > the use of XML for the web.config and other configuration files

    > that
    >> >> >> > ASP.Net
    >> >> >> > and .Net in general uses.
    >> >> >> >
    >> >> >> > In fact, using the web.config file might be your best bet to
    >> >> >> > begin
    >> >> >> > with.
    >> >> >> > You
    >> >> >> > can easily use the built-in "appSettings" element in the

    > web.config
    >> > to
    >> >> >> > define your own data, which can easily be read from the file at

    > run
    >> >> > time.
    >> >> >> > Example:
    >> >> >> >
    >> >> >> > <?xml version="1.0" encoding="utf-8" ?>
    >> >> >> > <configuration>
    >> >> >> > <appSettings>
    >> >> >> > <add key="ConnectionString"
    >> >> >> > value="server=blah;uid=Blah;pwd=blahblah;database=blah"/>
    >> >> >> > <add key="VoyagerPath" value="C:\VoyagerOnline" />
    >> >> >> > <add key="Timeout" value="15" />
    >> >> >> > </appSettings>
    >> >> >> > ...
    >> >> >> >
    >> >> >> > These configuration elements are easy to fetch at run-time.

    > Example:
    >> >> >> >
    >> >> >> > Dim Timeout As int =
    >> >> >> > System.Configuration.ConfigurationSettings.AppSettings("Timeout")
    >> >> >> >
    >> >> >> > You can also define custom configuration sections, if you have a

    > lot
    >> > of
    >> >> >> > data
    >> >> >> > and need to organize it into a nice tree hierarchy.
    >> >> >> >
    >> >> >> > --
    >> >> >> > HTH,
    >> >> >> > Kevin Spencer
    >> >> >> > .Net Developer
    >> >> >> > Microsoft MVP
    >> >> >> > I get paid good money to
    >> >> >> > solve puzzles for a living
    >> >> >> >
    >> >> >> > "Davíð Þórisson" <> wrote in message
    >> >> >> > news:...
    >> >> >> >> now in my web I have some global variables to be used in many
    >> >> >> >> different
    >> >> >> >> subpages, in the old ASP I simply loaded a variables.asp file

    > into
    >> >> > memory
    >> >> >> >> using the eval() function. Now I'd like to use XML but what

    > method
    >> >> > would
    >> >> >> >> I
    >> >> >> >> use to load the entries from the xml file into memory and make

    > them
    >> >> >> > quickly
    >> >> >> >> accessible globally in the web code? Just need to know what
    >> > functions
    >> >> >> >> specifically I should start reading about!
    >> >> >> >>
    >> >> >> >> Thx
    >> >> >> >>
    >> >> >> >>
    >> >> >> >
    >> >> >> >
    >> >> >>
    >> >> >>
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
    Davíð Þórisson, Oct 26, 2004
    #17
  18. Aha! Well, there you go. Nice work, David.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    I get paid good money to
    solve puzzles for a living

    "Davíð Þórisson" <> wrote in message
    news:...
    > no prob Kevin, I understand.
    > After some Googling I finally managed to solve this although I don't know

    at
    > all why. What I did was changing:
    > <section name="mySection"
    > type="System.Configuration.NameValueSectionHandler,System/>
    > to:
    > <section name="mySection"
    > type="System.Configuration.NameValueSectionHandler,System,
    > Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089,
    > Custom=null" />
    >
    > god knows what that Version bla bla does but it works!!! (I always thought
    > XML was sooo easy and clean code)
    >
    > "Kevin Spencer" <> wrote in message
    > news:...
    > > Hi David,
    > >
    > > I'm afraid I don't help people by email, for a number of reasons too

    long
    > > to
    > > go into here.
    > >
    > > I will be happy to continue helping you on this newsgroup, however, if
    > > you
    > > can tell me where you're having trouble. the article (and related
    > > articles)
    > > should give you what you need to know. The section head for the article

    I
    > > pointed you to is at:
    > >
    > >

    http://msdn.microsoft.com/library/e...onconfigurationsectionhandlers.asp?frame=true
    > >
    > > but I can also answer any specific questions you may have.
    > >
    > > --
    > > HTH,
    > > Kevin Spencer
    > > .Net Developer
    > > Microsoft MVP
    > > I get paid good money to
    > > solve puzzles for a living
    > >
    > > "Davíð Þórisson" <> wrote in message
    > > news:...
    > >> Kevin
    > >> could you kindly email me, I'm so close to getting this done (the using
    > >> statement is there) still some error I can't figure out :(
    > >>
    > >>
    > >> "Kevin Spencer" <> wrote in message
    > >> news:...
    > >> > If the type cannot be found, one or both of 2 things is happening.

    > > Either
    > >> > you haven't referenced the assembly (DLL), or you haven't added a

    using
    > >> > statement to negate the necessity of using the complete NameSpace
    > >> > hierarchy
    > >> > in your code. The complete NameSpace for NameValueCollection is
    > >> > "System.Collections.Specialized.NameValueCollection".
    > >> >
    > >> > --
    > >> > HTH,
    > >> > Kevin Spencer
    > >> > .Net Developer
    > >> > Microsoft MVP
    > >> > I get paid good money to
    > >> > solve puzzles for a living
    > >> >
    > >> >
    > >> > "Davíð Þórisson" <> wrote in message
    > >> > news:#...
    > >> >> I have to admit this is far beyond my knowledge so I just try to

    copy
    > >> >> &
    > >> >> paste with some common sense... so far I've got the xml file correct

    > > but
    > >> >>
    > >> >> NameValueCollection sampleConfig =
    > >> >>
    > >> >

    > >

    (NameValueCollection)ConfigurationSettings.GetConfig("mySectionGroup/myWeb1"
    > >> > );
    > >> >> string strKeyValue = (string)sampleConfig["Title"];
    > >> >> myLabel.Text = myVar;
    > >> >>
    > >> >> just brings on an error (surprise): "The type or namespace name
    > >> >> 'NameValueCollection' could not be found (are you missing a using
    > >> > directive
    > >> >> or an assembly reference?)"
    > >> >>
    > >> >>
    > >> >> "Kevin Spencer" <> wrote in message
    > >> >> news:%...
    > >> >> > Correct. Remember I mentioned that you can create your own
    > >> >> > customized
    > >> >> > Sections? That's what you need here. See the following SDK article

    > > for
    > >> >> > more
    > >> >> > information about how:
    > >> >> >
    > >> >> >
    > >> >

    > >

    http://msdn.microsoft.com/library/d.../cpguide/html/cpcondeclaringsectiongroups.asp
    > >> >> >
    > >> >> > --
    > >> >> > HTH,
    > >> >> > Kevin Spencer
    > >> >> > .Net Developer
    > >> >> > Microsoft MVP
    > >> >> > I get paid good money to
    > >> >> > solve puzzles for a living
    > >> >> >
    > >> >> > "Davíð Þórisson" <> wrote in message
    > >> >> > news:...
    > >> >> >> Kevin, so far so good but .Net doesn't allow me to split the
    > >> > appsettings
    > >> >> >> into subgroups eg
    > >> >> >> <appSettings>
    > >> >> >> <Web1Group>
    > >> >> >> <add key="Title" value="Title of web 1"/>
    > >> >> >> ...
    > >> >> >> </Web1Group>
    > >> >> >> <Web2Group>
    > >> >> >> <add key="Title" value="Title of web 2"/>
    > >> >> >> ...
    > >> >> >> </Web2Group>
    > >> >> >> </appSettings>
    > >> >> >>
    > >> >> >> The error I get: "Unrecognized element."
    > >> >> >>
    > >> >> >>
    > >> >> >>
    > >> >> >> "Kevin Spencer" <> wrote in message
    > >> >> >> news:...
    > >> >> >> > My apologies, David.
    > >> >> >> >
    > >> >> >> > After re-reading your question and my response, I can see that

    I
    > > was
    > >> >> >> > not
    > >> >> >> > answering the question you asked, which is how to read data
    > >> >> >> > stored
    > >> >> >> > in
    > >> >> >> > an
    > >> >> >> > XML
    > >> >> >> > file INTO memory, which is something altogether different from
    > >> > storing
    > >> >> > XML
    > >> >> >> > data IN memory. Reading it from a file is a great idea, as
    > >> > exemplified
    > >> >> > by
    > >> >> >> > the use of XML for the web.config and other configuration files

    > > that
    > >> >> >> > ASP.Net
    > >> >> >> > and .Net in general uses.
    > >> >> >> >
    > >> >> >> > In fact, using the web.config file might be your best bet to
    > >> >> >> > begin
    > >> >> >> > with.
    > >> >> >> > You
    > >> >> >> > can easily use the built-in "appSettings" element in the

    > > web.config
    > >> > to
    > >> >> >> > define your own data, which can easily be read from the file at

    > > run
    > >> >> > time.
    > >> >> >> > Example:
    > >> >> >> >
    > >> >> >> > <?xml version="1.0" encoding="utf-8" ?>
    > >> >> >> > <configuration>
    > >> >> >> > <appSettings>
    > >> >> >> > <add key="ConnectionString"
    > >> >> >> > value="server=blah;uid=Blah;pwd=blahblah;database=blah"/>
    > >> >> >> > <add key="VoyagerPath" value="C:\VoyagerOnline" />
    > >> >> >> > <add key="Timeout" value="15" />
    > >> >> >> > </appSettings>
    > >> >> >> > ...
    > >> >> >> >
    > >> >> >> > These configuration elements are easy to fetch at run-time.

    > > Example:
    > >> >> >> >
    > >> >> >> > Dim Timeout As int =
    > >> >> >> >

    System.Configuration.ConfigurationSettings.AppSettings("Timeout")
    > >> >> >> >
    > >> >> >> > You can also define custom configuration sections, if you have

    a
    > > lot
    > >> > of
    > >> >> >> > data
    > >> >> >> > and need to organize it into a nice tree hierarchy.
    > >> >> >> >
    > >> >> >> > --
    > >> >> >> > HTH,
    > >> >> >> > Kevin Spencer
    > >> >> >> > .Net Developer
    > >> >> >> > Microsoft MVP
    > >> >> >> > I get paid good money to
    > >> >> >> > solve puzzles for a living
    > >> >> >> >
    > >> >> >> > "Davíð Þórisson" <> wrote in message
    > >> >> >> > news:...
    > >> >> >> >> now in my web I have some global variables to be used in many
    > >> >> >> >> different
    > >> >> >> >> subpages, in the old ASP I simply loaded a variables.asp file

    > > into
    > >> >> > memory
    > >> >> >> >> using the eval() function. Now I'd like to use XML but what

    > > method
    > >> >> > would
    > >> >> >> >> I
    > >> >> >> >> use to load the entries from the xml file into memory and make

    > > them
    > >> >> >> > quickly
    > >> >> >> >> accessible globally in the web code? Just need to know what
    > >> > functions
    > >> >> >> >> specifically I should start reading about!
    > >> >> >> >>
    > >> >> >> >> Thx
    > >> >> >> >>
    > >> >> >> >>
    > >> >> >> >
    > >> >> >> >
    > >> >> >>
    > >> >> >>
    > >> >> >
    > >> >> >
    > >> >>
    > >> >>
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
    Kevin Spencer, Oct 26, 2004
    #18
    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. chris
    Replies:
    3
    Views:
    9,285
    Miha Markic
    Dec 5, 2003
  2. Wayne
    Replies:
    2
    Views:
    467
    Wayne
    Nov 11, 2003
  3. jose luis fernandez diaz

    Nonlocal Store (global and class static variables)

    jose luis fernandez diaz, Jan 2, 2004, in forum: C++
    Replies:
    8
    Views:
    1,223
    Victor Bazarov
    Jan 6, 2004
  4. jubelbrus
    Replies:
    5
    Views:
    608
    JohnQ
    Jul 20, 2007
  5. Yash
    Replies:
    1
    Views:
    115
Loading...

Share This Page