使用XML将全局变量存储在内存中 [英] Using XML to store global variables in memory

查看:120
本文介绍了使用XML将全局变量存储在内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在在我的网上我有一些全局变量用于许多不同的

子页面,在旧的ASP中我只是将一个variables.asp文件加载到内存中

使用eval()函数。现在我想使用XML,但是我会用什么方法将
用于将xml文件中的条目加载到内存中并快速使用它们在Web上全局访问
码?只需要知道具体的功能

我应该开始阅读!


Thx

解决方案

XmlDocument类及其方法(如Load和LoadXML)。另一方面

我不知道为什么Xml? XML是很多东西,所有这些都很棒,但是它几乎不是保留一堆变量的最好方法。

创建一个类会更好,使你的变量成为这个类的成员(属性)和

将你的calss附加到Session或Application。我通常也会在类上使用字符串id声明

一个静态成员,该字符串用于从应用程序集合中访问该类的

对象。通过这种方式你完全可以防止你在字符串中出现错别字


HTH,Michael


" Dav ?*?°3risson"写道:

现在在我的网上我有一些全局变量用于许多不同的子页面,在旧的ASP中我只是将一个variables.asp文件加载到内存中<使用eval()函数。现在我想使用XML,但是我会用什么方法将xml文件中的条目加载到内存中并使它们能够在Web代码中快速访问?只需要知道具体的功能
我应该开始阅读!



Thx迈克尔,

你看到我在同一个应用程序上有几个网页(使用相同的

核心,但不同的布局和网址),以便变量根据

它是哪个网站。我希望能够快速访问特定的网页

变量,例如

string Title = Web1.Title ...


而不是有几个标题,例如

string TitleForWeb1

string TitleForWeb2 ...


这就是想法!


" mfeingold" < MF ******* @ discussions.microsoft.com>在消息中写道

新闻:9D ********************************** @ microsof t.com ...

XmlDocument类及其方法(如Load和LoadXML)。另一方面
我不确定Xml为什么? XML是很多东西,所有这些都很棒,但它几乎不是保留一堆变量的最佳方法。你最好创建一个类,使你的变量成为这个类的成员(属性)

将你的calss附加到Session或Application。我通常也会在类上声明一个静态成员,其中包含字符串id,用于从应用程序集合中访问该类的对象。通过这种方式,你可以完全保护你的字符串中的拼写错误

HTH,Michael

DavíeTórisson写道:

现在在我的网上我有一些全局变量用于许多不同的子页面,在旧的ASP中我只是将一个variables.asp文件加载到内存中<使用eval()函数。现在我想使用XML,但是我会用什么方法将xml文件中的条目加载到内存中,并使它们能够快速地在Web上全局访问码?只需要知道具体的功能
我应该开始阅读!

Thx



好吧,使用xml你必须写一些类似

MyXmlDoc [" Web1"]。属性[" Title"]。值

假设MyXmlDoc是你的文件看起来像

< root>< Web1 Title =" ...." />< Web2 Title =" ..." />< ; / root>

很多编码到底是什么?你仍然可以输错属性名称或节点

名称和编译器不会告诉你一个事情

另一方面与类 - 你可以定义方法

喜欢getTitle,它会将网页名称作为参数,甚至抛出

异常通知你网页名称不正确


Dav?*?°?3risson写道:

Thx迈克尔,
你看到我在同一个应用程序上有几个网站(使用相同的核心但不同的布局和网址),以便变量根据网络的不同而不同。我希望能够快速访问特定于网络的变量,例如
字符串Title = Web1.Title ...

而不是拥有多个标题,例如
字符串TitleForWeb1
字符串TitleForWeb2 ......

这就是想法!

" mfeingold" < MF ******* @ discussions.microsoft.com>在消息中写道
新闻:9D ********************************** @ microsof t.com。 ..

XmlDocument类及其方法(如Load和LoadXML)。另一方面
我不确定Xml为什么? XML是很多东西,所有这些都很棒,但它几乎不是保留一堆变量的最佳方法。你最好创建一个类,使你的变量成为这个类的成员(属性)

将你的calss附加到Session或Application。我通常也会在类上声明一个静态成员,其中包含字符串id,用于从应用程序集合中访问该类的对象。通过这种方式,你可以完全地保护你的字符串中的拼写错误

HTH,Michael

Dav?*?°??? 3risson ;写道:

现在在我的网上我有一些全局变量用于许多不同的子页面,在旧的ASP中我只是将一个variables.asp文件加载到内存中<使用eval()函数。现在我想使用XML,但是我会用什么方法将xml文件中的条目加载到内存中,并使它们能够快速地在Web上全局访问码?只需要知道我应该开始阅读哪些功能





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

解决方案

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?*?° ???3risson" 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



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*******@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.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(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íe Tó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



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?*?° ???3risson" 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*******@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.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(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?*?° ???3risson" 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




这篇关于使用XML将全局变量存储在内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆