XML IntelliSense in Visual Basic provides word completion for elements that are defined in an XML schema. To enable XML IntelliSense in Visual Basic, you must do the following:
Obtain the XML schema (XSD) file or files for the XML files that your application will read from or write to.
Include the XML schema files in your project.
Import the target namespace or namespaces into your code file or project. A target namespace is identified by the
tnsattribute of your XSD schema.
To import a target namespace, use the
Importsstatement, or add a namespace for all code files in a project by using the References page of the Project Designer.
For more information on the capabilities of XML IntelliSense in Visual Basic, see XML IntelliSense in Visual Basic. For more information on importing XML namespaces, see Imports Statement (XML Namespace) or References Page, Project Designer (Visual Basic).
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Personalizing the IDE.
For a video version of this topic, see Video How to: Enable XML IntelliSense in Visual Basic. For a related video demonstration, see How Do I Enable XML IntelliSense and Use XML Namespaces?.
Enable XML IntelliSense in Visual Basic
If you have an XML file but you do not have an XSD schema file for it, in SP1 you can create an XSD schema file by using the XML to Schema Wizard. You can also use schema inference in the Visual Studio XML Editor.
To create an XSD schema file for an XML file by using the XML to Schema Wizard (requires SP1)
In your project, click Add New Item on the Project menu.
Select the Xml to Schema item template from either the Data or Common Items template categories.
Provide a file name for the XSD file or files that the inferred schema set will be stored in, and then click Add.
In the Infer XML Schema set from XML documents window, add one or more XML documents to infer the XML schema set from.
To add text files that contain XML documents by using File Explorer, click Add from File.
To add an XML document from an HTTP address, click Add from Web.
To copy or type the contents of an XML document into the wizard, click Type or paste XML.
When you have specified all the XML document sources from which you want to infer the XML schema set, click OK to infer the XML schema set. The schema set is saved in your project folder in one or more XSD files. (For each XML namespace in the schema, a file is created.)
To create an XSD schema file for an XML file by using schema inference in the Visual Studio XML Editor
Edit the XML file in the Visual Studio XML Designer.
When the cursor is somewhere in the XML file, the XML menu appears. Click Create Schema on the XML menu. An XSD file is created from XSD schema inferred from the XML file.
Save the XSD schema file.
Different XSD schemas might be inferred from multiple XML documents that are intended to have the same schema. This can occur when particular elements and attributes are found in one XML file and not in another, or when elements are included in different order, for example. You should review inferred XSD schemas for completeness and accuracy when you use XSD schema inference.
To include an XSD schema file
By default, you cannot see XSD files in Visual Basic projects. If your XSD file is already included in the folders for your project, click the Show All Files button in Solution Explorer. Locate the XSD file in Solution Explorer, right-click the file, and click Include File in Project.
If your XSD file is not already part of your project, in Solution Explorer, right-click the folder in which you want to store the XSD file, point to Add, and then click Existing Item. Locate your XSD file and then click Add.
To import an XML namespace in a code file
Identify the target namespace from your XSD schema.
At the beginning of the code file, add an
Importsstatement for the target XML namespace, as shown in the following example.
To import an XML namespace as the default namespace, that is, the namespace that is applied to XML elements and attributes that do not have a namespace prefix, add an
Importsstatement for the target default XML namespace. Do not specify a namespace prefix. Following is an example of an
To import an XML namespace for all files in a project
An XML namespace imported in a code file applies to that code file only. To import an XML namespace that applies to all code files in a project, open the Project Designer by double-clicking My Project in Solution Explorer.
On the References tab, in the Imported namespaces box, type the target XML namespace in the form of a full XML namespace declaration (for example,
<xmlns: ns="http://sampleNamespace">). If the target XML namespace does not specify a namespace prefix, the namespace will be the default XML namespace for the project.
Click Add User Import.