config file ?n

G

Guest

I have to do some screen scraping and I need to do it for more than 1 site.
I am making a call to WebRequest.Create(url) (to many urls) and I wanted to
put the urls, and the text that I use for the Regular expression in the
config file. But if the name is "site1" and the url is
"www.somesitewithalongurl.com" and the text I'm looking for is
"<title>sometitletext</title>", how can I use all 3 in the config file.

If I have the following in the config file,
<appSettings>
<add key="Site1" value="http://www.somesite with a long url.com"/>
<add key="Site2" value="http://www.another long url.com"/>
</appSettings>

and the following for screen scraping,
Urls = ConfigurationSettings.AppSettings["Site1"];

regex = new Regex(mytitletaginfo ,RegexOptions.IgnoreCase);

how can I add a 3rd attribute to the "add" xml tag, and how do I access it?
I'm thinking something like
<add key="Site1" value="http://www.somesitewithalongurl.com"/
value2="<title>sometitletext</title>">
But how do I access the value2 attribute using the ConfigurationSettings
static class.

Also if I add another site, I would rather not code it so I have to know
what the "key" attribute value is, so how do I iterate or loop over the
"add" xml tags and retrieve all 3 values, namely key, value, and value2.
Ultimately, I will be adding more urls and its associated <title> tags to
the app.config file and I can't go back to the code and recompile for new
urls.

Any help or links to articles discussing this will be greatly appreciated.
Thanks
gv
 
J

Jay B. Harlow [MVP - Outlook]

gv,
how can I add a 3rd attribute to the "add" xml tag, and how do I access it?
I'm thinking something like
Create a custom configuration section via configSections and implementing
the System.Configuration.IConfigurationSectionHandler. I would pattern the
custom section handler after DictionarySectionHandler (support: add, remove,
clear).

<siteSettings>
<add site="Site1" url="http://www.somesite with a long url.com"
title="Site 2 title" />
<add site="Site2" url="http://www.another long url.com"
title="Site 2 title" />
</siteSettings>

Then within your code you can use ConfigurationSettings.GetConfig to return
the above section of the app.config. Depending on what you do in your
IConfigurationSectionHandler.Create method (I would create a HashTable) will
decide what GetConfig returns.

See the following on how to create new sections via the configSections
section.

http://msdn.microsoft.com/library/d...de/html/cpconconfigurationsectionhandlers.asp

and:
http://msdn.microsoft.com/library/d...ref/html/gngrfconfigurationsectionsschema.asp

Also read about the System.Configuration.ConfigurationSettings class and
other classes in the System.Configuration namespace.


Hope this helps
Jay


I have to do some screen scraping and I need to do it for more than 1 site.
I am making a call to WebRequest.Create(url) (to many urls) and I wanted to
put the urls, and the text that I use for the Regular expression in the
config file. But if the name is "site1" and the url is
"www.somesitewithalongurl.com" and the text I'm looking for is
"<title>sometitletext</title>", how can I use all 3 in the config file.

If I have the following in the config file,
<appSettings>
<add key="Site1" value="http://www.somesite with a long url.com"/>
<add key="Site2" value="http://www.another long url.com"/>
</appSettings>

and the following for screen scraping,
Urls = ConfigurationSettings.AppSettings["Site1"];

regex = new Regex(mytitletaginfo ,RegexOptions.IgnoreCase);

how can I add a 3rd attribute to the "add" xml tag, and how do I access it?
I'm thinking something like
<add key="Site1" value="http://www.somesitewithalongurl.com"/
value2="<title>sometitletext</title>">
But how do I access the value2 attribute using the ConfigurationSettings
static class.

Also if I add another site, I would rather not code it so I have to know
what the "key" attribute value is, so how do I iterate or loop over the
"add" xml tags and retrieve all 3 values, namely key, value, and value2.
Ultimately, I will be adding more urls and its associated <title> tags to
the app.config file and I can't go back to the code and recompile for new
urls.

Any help or links to articles discussing this will be greatly appreciated.
Thanks
gv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top