170 likes | 242 Views
Introduction To XML and using web.config file. Topics. What is XML History Motivation Where/Who uses XML When to use/not use. What Is XML. Data formatted in a way that is easy for humans and machines to read eXtensible Markup Language Text data, i.e. not binary
E N D
Topics • What is XML • History • Motivation • Where/Who uses XML • When to use/not use
What Is XML • Data formatted in a way that is easy for humans and machines to read • eXtensible Markup Language • Text data, i.e. not binary • When stored in a file, one can view it with Notepad • Not a language • Fast becoming a universal data translation language
Example <?xml version="1.0"?> <CustomerList> <customer id="1"> <fname> Jen </fname> <lname> Lo </lname> <title> CEO </title> <company> Blue Moon Enterprises </company> </customer> <customer id="2"> <fname> Austin </fname> <lname> Powers </lname> <title> Gold Member </title> <company> MiniEvil </company> </customer> </CustomerList>
XML’s History • Specs published in Feb 1998 • Began to get popular in 2000 • Supported by most vendors and platforms • MS, IBM, Sun, Borland, … • I.E. >= 5.0 can display XML data
Motivation • Businesses needed to communicate over the Internet. (B2B) • Send documents and complex data that have different formats • Word, PDF, Excel, Access, comma separated, … • E.g. think how many ways a person’s name can be formatted • Different Internet clients capabilities. • Desktops with different browsers • PDAs, Mobile phones, …
Where/Who Uses XML • In databases to store or move data • In configuration files • In communication between systems • MS: .NET, IE, SQL Server, …
To Use Or Not To Use • Use when you want to: • Communicate between different programs and systems • Store complex configuration data • Display output by different clients, e.g. desktops and PDAs. • Do not use when: • You need a relational database model, XML is less efficient than RDBs
XML Technologies • The following slides will introduce some XML related terms and technologies • This a high level definition
Tags And Elements Consider the following XML snippet: <customer id="2"> <fname> Austin </fname> <lname> Powers </lname> <title> Gold Member </title> <company> MiniEvil </company> </customer> • <fname> is a start tag • </fname> is an end tag • <fname>Austin</fname> is an element • id (in customer tag) is an attribute
Well-Formed XML Document • Well-Formed document: • Follows XML syntax • Every start tag must have an end tag • If a document is not well-formed, then it is NOT an XML document
Web.config file • Web.config is the main settings and configuration file for an ASP.NET web application. • The file is an XML document that defines configuration information regarding the web application. • The web.config file contains information that control module loading, security configuration, session state configuration, and application language and compilation settings. • Web.config files can also contain application specific items such as database connection strings.
Web.config File <configuration> • <appSettings> • <add key="abc" value=“a certain value"/> • </appSettings> • <connectionStrings> • <add name="TestingConnectionString1" connectionString="Data Source=.;Initial Catalog=Testing;Integrated Security=True" providerName="System.Data.SqlClient"/> • </connectionStrings> • <system.web> • <compilation debug="true" strict="false" explicit="true"/> • <pages> • <namespaces> • <clear/> • <add namespace="System"/> • <add namespace="System.Collections"/> • <add namespace="System.Collections.Specialized"/> • <add namespace="System.Configuration"/> • <add namespace="System.Text"/> • <add namespace="System.Text.RegularExpressions"/> • <add namespace="System.Web"/> • <add namespace="System.Web.Caching"/> • <add namespace="System.Web.SessionState"/> • <add namespace="System.Web.Security"/> • <add namespace="System.Web.UI"/> • <add namespace="System.Web.UI.WebControls"/> • <add namespace="System.Web.UI.WebControls.WebParts"/> • <add namespace="System.Web.UI.HtmlControls"/> • </namespaces> • </pages> • <authentication mode="Windows"/> • </system.web> </configuration>
Web.config File • At this point, we are interested in the web.config part that is highlighted in red in the previous example. • appSettings section • Contains custom application settings, such as file paths, XML Web service URLs.
Web.config File • Ex) <appSettings> <add key=“imgsPath" value=“~/images/"/> </appSettings> • connectionStrings section: • Specifies a collection of database connection strings, as name/value pairs, for ASP.NET applications and features.
Web.config File • Ex) <connectionStrings> <add name=“connStr“ connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Testing;Integrated Security=True" providerName="System.Data.SqlClient"/> </connectionStrings>
Web.config File • To retrieve a value from appSettings section and use it in ASP.NET code: ConfigurationManager.AppSettings(“app_name") • To retrieve a value from connectionString section and use it in ASP.NET code: ConfigurationManager.ConnectionStrings(“conStr").ConnectionString