Solved

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

Posted on 2010-08-18
3
464 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now