473,781 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using XML to store global variables in memory

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
Nov 18 '05 #1
17 2460
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(propert ies) 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

Nov 18 '05 #2
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" <mf*******@disc ussions.microso ft.com> wrote in message
news:9D******** *************** ***********@mic rosoft.com...
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(propert ies) 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

Nov 18 '05 #3
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" <mf*******@disc ussions.microso ft.com> wrote in message
news:9D******** *************** ***********@mic rosoft.com...
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(propert ies) 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


Nov 18 '05 #4
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" <mf*******@disc ussions.microso ft.com> wrote in message
news:26******** *************** ***********@mic rosoft.com...
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" <mf*******@disc ussions.microso ft.com> wrote in message
news:9D******** *************** ***********@mic rosoft.com...
> 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(propert ies) 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
>>
>>
>>


Nov 18 '05 #5
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" <db**@hi.is> wrote in message
news:eV******** ******@TK2MSFTN GP12.phx.gbl...
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" <mf*******@disc ussions.microso ft.com> wrote in message
news:26******** *************** ***********@mic rosoft.com...
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" <mf*******@disc ussions.microso ft.com> wrote in message
news:9D******** *************** ***********@mic rosoft.com...
> 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(propert ies) 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
>>
>>
>>


Nov 18 '05 #6
One way of doing this would be to create a class and inherit it from
System.Web.UI.P age somthing like this:

public class MyPageClass : System.Web.UI.P age
{

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

override protected void OnInit(EventArg s 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.P age) 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" <db**@hi.is> wrote in message
news:eV******** ******@TK2MSFTN GP12.phx.gbl...
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" <mf*******@disc ussions.microso ft.com> wrote in message
news:26******** *************** ***********@mic rosoft.com...
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" <mf*******@disc ussions.microso ft.com> wrote in message
news:9D******** *************** ***********@mic rosoft.com...
> 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(propert ies) 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
>>
>>
>>



Nov 18 '05 #7
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.Tra yHeight" type="System.In t32, mscorlib,
Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9">
<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" <db**@hi.is> wrote in message
news:eh******** *****@TK2MSFTNG P11.phx.gbl...
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

Nov 18 '05 #8
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 "appSetting s" 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" ?>
<configuratio n>
<appSettings>
<add key="Connection String"
value="server=b lah;uid=Blah;pw d=blahblah;data base=blah"/>
<add key="VoyagerPat h" value="C:\Voyag erOnline" />
<add key="Timeout" value="15" />
</appSettings>
....

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

Dim Timeout As int =
System.Configur ation.Configura tionSettings.Ap pSettings("Time out")

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" <db**@hi.is> wrote in message
news:eh******** *****@TK2MSFTNG P11.phx.gbl...
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

Nov 18 '05 #9
exactly Kevin, sounds exactly like I need and want to do... so simple and
elegant solution - thx!
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:uv******** *****@TK2MSFTNG P15.phx.gbl...
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 "appSetting s" 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" ?>
<configuratio n>
<appSettings>
<add key="Connection String"
value="server=b lah;uid=Blah;pw d=blahblah;data base=blah"/>
<add key="VoyagerPat h" value="C:\Voyag erOnline" />
<add key="Timeout" value="15" />
</appSettings>
...

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

Dim Timeout As int =
System.Configur ation.Configura tionSettings.Ap pSettings("Time out")

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" <db**@hi.is> wrote in message
news:eh******** *****@TK2MSFTNG P11.phx.gbl...
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


Nov 18 '05 #10

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

Similar topics

8
2536
by: jose luis fernandez diaz | last post by:
Hi, I am reading Stroustrup's book 'C++ Programming Language'. In the 10.4.9 section (Nonlocal Store) he says: "A variable defined outside any function (that is global, namespace, and class static variables) is initializated (constructed) before main is invoked . . ." .. . .
9
6901
by: Charley Kyd | last post by:
I'm a newbie who needs advice about how to use external files of JavaScript code. I spent an hour this afternoon browsing through JavaScript books at the local book store. In about 15 different titles, I found a total of about five pages that covered js files. For all practical purposes, these pages said, "You can use js files. But we won't tell you how." Therefore, I hope someone can answer a few questions about js files... 1....
4
1968
by: gsyoon | last post by:
hi, all. I'm trying to make a "framework" to store the return value of a function to a global memory. My first attempt was 1) void store_to_global( char * type_name ) { if ( strcmp( type_name, "CLASS_A") )
5
3495
by: j | last post by:
Anyone here feel that "global variables" is misleading for variables whose scope is file scope? "global" seems to imply global visibility, while this isn't true for variables whose scope is file scope. If you have a variable whose scope is file scope in another translation unit, you have to provide a local declaration to access that variable from the other translation unit. Also, I don't see "global variable" used once in the standard....
20
3504
by: Sushil | last post by:
Hi gurus I was reading FAQ "alloca cannot be written portably, and is difficult to implement on machines without a conventional stack." I understand that the standard does not mandate "heap" or "stack" I'm curious to know the implemenations which dont have stack or heap.
3
2004
by: Pavan | last post by:
Hi i would like to know abt the data variable storage in C like 1.where does global variables gets stored and why is it so .. 2.like wise static ,local variables, as for as i know i remember that localvariables/functionarguments gets stored in stack is it true then how abt this lets go with an explicit example since it can give me a exact answers
8
4871
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical differences in the way both the objects are handled by IIS. Are both objects stored in different memory spaces? I can access both the objects in my web page. I will be grateful if some one can help me understand the difference.
3
1687
by: Daves | last post by:
Please take your time to read the following, it's simple although the text is 3 paragraphs... Everytime an user is logged in I need to make a call to my sql server database to grab some specific user settings and load into Session variables. So, I have a "Loggedin" event in login.aspx which does this. As users can be logged in (automatically) via HttpApplication & Cookies, I need to run this same code after that. I can put the same code...
3
14762
by: frothpoker | last post by:
Guys, I'm sure this has been asked a million times but I can't seem to formulate a google search that returns what i'm looking for. I've go a dev and live environment. Currently the DB connect string is hard coded into each php file which means i'm going to have to change every page - Arrgh!! If i put the DBonnect into a function and store it in an include file,
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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

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