Reputation: 31033
i have been given a task to make a resource xml file for the static content of our website so that we can look-up for the content in that xml file against a particular id and display it. For example if we have written "Welcome to xyz.com" on our home page it should be stored in the xml file like
<word>
<add Key="welcome" value="Welcome to xyz.com" />
</word>
<word>
<add key="key1" value="some other static content" />
</word>
so we will be able to display the text by id="welcome"... plz help.
accessing the resource file as
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);
and getting the following error
Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.
baseName: Resource locationInfo: <null> fileName: Resource.resources
Upvotes: 0
Views: 1704
Reputation: 84
Try an XML format like this:
<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>
Why? My first thought is that each page needs it own id. So I have shown a page called "Home" with two Elements. Also by using tags rather than attributes sou can use CDATA sections [http://en.wikipedia.org/wiki/CDATA] in case you have characters that need to be escaped. Otherwise you'll have to transform <,>,& and that gets ugly.
<Element Id="key1">
<Value><![CDATA[some other static content with < > in it!]]></Value>
</Element>
Or how about it you want to include a div? with a class?
<Element Id="key1">
<Value><![CDATA[<div class="wrapper">some other static content with in it!</div>]]></Value>
</Element>
It's better.
In general, I use tags more than attributes. It's easier to find tags using XPath.
Upvotes: 3