Solved

can I store an xsd file in an app.config file?  If so, how

Posted on 2010-08-18
3
467 Views
Last Modified: 2013-12-17
How can I store an xsd file in my app.config file (since it is xml)?  Also, how do I read it out?

Also, I am using this code to validate my xml.  How could I do that if I was using an app.config file since I will now have a file instead of a path for the "schemaFileName" argument.

                XmlSchemaSet sc = new XmlSchemaSet();
                sc.Add(targetNamespace, schemaFileName);

                XmlReaderSettings settings = new XmlReaderSettings();
                settings.Schemas = sc;
                settings.ValidationType = ValidationType.Schema;
0
Comment
Question by:jackjohnson44
  • 2
3 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 33466783
One method would be to encode it as a string - the Uri class has encode/decode functions available you could use.....this method sacrifices readability, though, and requires the encode to be done outside of your app to get it in....
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 33466890
A more readable possibility would be to roll your own config section, and include the xsd or xsds as part of it...this would require you to implement a class derived from ConfigurationSection to deal with it.
0
 
LVL 3

Accepted Solution

by:
GoJoeIsBlue earned 500 total points
ID: 33467812
If you are using "Visual Studio 2008" or "Visual Studio 2010" this is pretty easy, just do this:
1) Open your XSD-file
2) Select all content and copy
3) Right-click your project-file in Visual Studio's Solution Explorer and select "Properties" (located at the bottom)
4) Click the "Settings" tab in the properties window.
5) If all you see is a link, click the link and proceed
6) You a now precented with a grid consisting of the columns: Name, Type, Scope and Value
7) In "Name" type what ever you like your application setting to be called, eg. "MyXSD"
8) In "Type" choose "string", this should be the default choice
9) In "Scope" choose "User" if you plan to change the setting programatically, otherwise choose "Application"
10) In "Value" - paste your copied XSD-content
11) Hit CTRL+S which saves the settings

The above enables you to reach your settings like this:
string xsd = Properties.Settings.Default.MyXSD;

And  if your chose "User" as scope you can also do this:
Properties.Settings.Default.MyXSD = "<xs:schema ....> ... </xs:schema>";
Properties.Settings.Default.Save();
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
location of a form 2 32
Syntax Issue with SSIS module 26 134
Code works but breaks when I add one section 4 27
ASP.NET Built-In Report Creator / Viewer 5 17
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question