资源xml文件
问题描述:
我已经给了一个任务,为我们的网站的静态内容制作一个资源xml文件,以便我们可以查找该xml文件中针对特定id的内容并显示它。例如,如果我们写我们的主页上“欢迎来到xyz.com”应该存储在XML文件中像资源xml文件
<word>
<add Key="welcome" value="Welcome to xyz.com" />
</word>
<word>
<add key="key1" value="some other static content" />
</word>
,所以我们将能够显示由ID =“欢迎”的文本.. plz帮助。
访问资源文件
string key = "Home";
string resourceValue = string.Empty;
string resourceFile = "Resource";//name of my resource file Resource.resx
string filePath =System.AppDomain.CurrentDomain.BaseDirectory.ToString();
ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile, filePath, null);
resourceValue = resourceManager.GetString(key);
,并收到以下错误
Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.
baseName: Resource locationInfo: <null> fileName: Resource.resources
答
尝试像这样的XML格式:
<Page Id="Home">
<Elements>
<Element Id="welcome">
<Value>Welcome to xyz.com</Value>
</Element>
<Element Id="key1">
<Value>some other static content</Value>
</Element>
</Elements>
</Page>
为什么?我的第一个想法是每个页面都需要它自己的ID。所以我用两个元素显示了一个名为“Home”的页面。也可以使用标签而非属性,如果您有需要转义的字符,可以使用CDATA部分[http://en.wikipedia.org/wiki/CDATA]。否则,你将不得不转换<,>,&,那会变得很难看。
<Element Id="key1">
<Value><![CDATA[some other static content with < > in it!]]></Value>
</Element>
或者如果你想包括一个div?上课?
<Element Id="key1">
<Value><![CDATA[<div class="wrapper">some other static content with in it!</div>]]></Value>
</Element>
它更好。
通常,我使用的标签不仅仅是属性。使用XPath查找标签更容易。
+0
tnx安东尼,我会尝试你的溶胶,希望它的工作原理 – Rafay 2010-11-06 05:33:50
你还没有真正问过一个具体的问题。你有什么麻烦? – 2010-11-04 07:12:07
研究在Visual Studio中使用资源(resx)文件。 – 2010-11-04 08:19:28
我不知道该怎么做,我认为生病必须使用XML读取器,但具体到底是什么? – Rafay 2010-11-04 09:31:40