2.2 HTML/XML EditorThe HTML/XML language service provides IntelliSense. For embedded client-side script in HTML, this works in much the same way as it does for any other programming language. And although the tags in HTML and XML documents do not constitute a programming language as such, VS.NET will still provide IntelliSense for tag and attribute names when it can. 2.2.1 HTML Script-Only ViewThe HTML navigation bar has two buttons on the right side. If you press the leftmost button, you can get a script-only view of your HTML—all of the HTML display elements will be hidden, leaving just the client-side script, as Figure 2-6 shows. If you select the rightmost button, nothing will be hidden. Figure 2-6. HTML script-only editor view2.2.2 HTML ViewsThe HTML editor can present two views of your page. It can present a raw text view, or it can show the page as it will appear in the browser. You can select the view you want by clicking on the HTML or Design button—they appear at the bottom left of the editor. (Or you can use Ctrl-PageUp or Ctrl-PageDown.) Even though the design view shows the page as it will appear in a browser, you can still use it to edit any text on the page—it provides WYSIWYG text editing. 2.2.3 Schemas, Validation, and IntelliSenseIf you select View Properties Window (F4) while in the XML or HTML editor, you will get a special property window that is different from the one you will see if you select the file in the Solution Explorer. The properties are different for HTML and XML files, but they do have one property in common: targetSchema. Visual Studio .NET uses this property to work out how to validate the document. It also uses it to determine which elements to display in IntelliSense member lists.
Validation and IntelliSense get their type information from XML Schema Definition files for both XML and HTML files. These schemas are stored under the \Common7\Packages\schemas folder in the VS.NET installation directory. (There are two subdirectories, html and xml.) The targetSchema property determines which of the schema files in these directories will be used, although the property works differently for HTML and XML files. With HTML files, the targetSchema property has a drop-down list showing a variety of browser versions. For example, you can choose to restrict yourself to Version 3 browser features, or you can validate for Netscape 4.0. If you select a targetSchema using the Properties pane, VS.NET will add a meta tag to your document named vs_targetSchema to indicate which schema is in use. (It stores the schema file's targetNameSpace in this tag, so if you want to add an extra schema of your own, simply make sure it has a unique targetNameSpace, and place it in the html directory along with the other schemas. You may also wish to add a vs:friendlyname attribute—VS.NET will display whatever string you put here in the drop-down list of schemas in the Properties panel.)
With XML files, validation is driven off the document element's namespace. Unfortunately, VS.NET ignores the standard schemaLocation and noNamespaceSchemaLocation attributes—a schema must be present in the xml schema directory in order to be used for IntelliSense and validation. Also, note that VS.NET cannot use a Document Type Definition (DTD) to provide validation or IntelliSense—it supports only schemas. 2.2.4 XML Data ViewThe XML editor can present a file's contents in an editable grid control. This allows you to put in element and attribute values without having to edit the XML document itself. Consider the following XML: <?xml version="1.0" encoding="utf-8" ?> <foo> <quuz quuzatt="World"> <baz>Hello</baz> </quuz> <quuz quuzatt="Two"> <baz>One</baz> </quuz> </foo> If you select the data view (by clicking on the Data button at the bottom left of the editor), it will display the grid as shown in Figure 2-7. Figure 2-7. XML data view2.2.5 XML SchemaWhen you are editing an XML schema document, as well as being able to edit the raw XML, a special schema view is available. This allows you to define element types visually. It also allows you to add relations between those elements. The Toolbox will present an XML Schema tab whenever you edit an XSD file, providing you with schema items that can be dragged onto the design view. The schema view can be selected by clicking on the Schema button at the bottom right of the editor. It is shown in Figure 2-8. Figure 2-8. XML schema viewVisual Studio .NET can infer an XML schema from an XML file. When editing an XML file, the main menu will have an XML menu. If you select XML Create Schema, Visual Studio .NET will create a schema (XSD file) based upon your XML document's structure and will add the new file to your project. |