Working with XML in Visual Studio 2005


Creating an XML file in Visual Studio 2005 is as simple as picking the XML File option from the Add New Item window, which gives a standard editor, as seen in Figure 7.1.

Figure 7.1. Editing XML in Visual Studio 2005


Because this file doesn't contain a schema, you get no IntelliSense, but you can have Visual Studio 2005 create one for you, inferring the schema from the structure of the XML file. To create a schema, you use the Create Schema option from the XML menu. For example, the schema creation for the shippers XML file is shown in Figure 7.2. This file is not automatically added to the project, so you should make sure you save it. Schema editing does have IntelliSense, since the schema is a defined XML language.

Figure 7.2. The Shippers schema


The schema is created automatically in code view, but you can view this in the designer by selecting View Designer from the context menu; the designer is the default view (see Figure 7.3). The schema designer provides a way to work with schemas without knowing the actual schema language.

Figure 7.3. The schema designer


To use this schema in the XML file, you add a namespace by use of the xmlns attribute. For example:

<shippers xmlns:s="shippers.xsd">


When adding a namespace, you get a drop-down list of public schemas to choose from, but you can just type in your own, and once added you get full IntelliSense, which allows easier editing of the XML data. This is the same schema editor that you use when working with typed data sets.



ASP. NET 2.0 Illustrated
ASP.NET 2.0 Illustrated
ISBN: 0321418344
EAN: 2147483647
Year: 2006
Pages: 147

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net