The XML editor has a Design view, which represents the XML file simultaneously as a table with Node and Content columns and a tree. This helps make navigation and editing easier. Content and attribute values can be edited directly in the table cells, while pop-up menus on the tree elements give alternatives that are valid for that particular element.
For example, the Add child menu item will list only those elements from a DTD or XML schema which would be valid children at that point.
When you have an XML file associated with an XML schema or DTD file, certain tags and rules for that file have already been established, which is why the Design view can provide prompts (via a pop-up menu) for those tags. When you create an XML file that is not associated with an XML schema or DTD file, it has no tags or rules associated with it, so the Design view cannot provide prompts for specific tags, but it can provide prompts to create new elements and attributes.
For any XML file associated with an XML schema or DTD file, you can use the Design view to add any items defined in the XML schema or DTD (such as elements and attributes) to the XML file. You can also use it to add processing instructions and comments to all XML files.
To open and edit a XML file in the XML editor, right-click the file in the Project Explorer view and click Open With > XML Editor. If necessary, click the Design tab to open the Design view.
To expand all the items in your XML file, click the Expand All button on the top right corner of the editor. To collapse them, click the Collapse All button on the top right corner of the editor.
If you right-click the item that you want to work with, some or all of the following options (as applicable) will be available from the pop-up menu that appears:
Select this | If you want to do this |
---|---|
Add DTD Information | Associate the XML file with a DTD. |
Edit DOCTYPE | Edit the DOCTYPE declaration. Refer to the related task for more details. For more information, see Editing DOCTYPE declarations. |
Edit Namespaces | Edit the existing namespace information or create a new association with a namespace. Refer to the related task for more details. For more information, see Editing namespace information. |
Edit Processing Instruction | Edit the processing instruction. Refer to the related task for more details. For more information, see Editing XML processing instructions. |
Remove | Remove the item that you have selected from the XML file. If the selected item or related items are defined so that the item must exist in the file, this option will not be available. For example, in your DTD, if you have declared that "One or more" of the item must always exist in your XML file, and the item you have selected is the only one that exists in your XML file. |
Add Attribute | Add an attribute to the element that you selected. Any attributes you are allowed to add to the element will be listed. After you have added the attribute to the XML file, you can click in the right-hand column to change the value of the attribute. If the attribute has set values, they will appear in a list. |
Add Child | Add another element, a comment, or a processing instruction as a child of the parent element. |
Add Before | Add a child element, comment, or processing instruction that can go before the item you have selected. For example, if you have a parent element called CD Collections that can contain an unlimited amount of children called CD, you could click a CD element and click | , as a CD element can go before another CD element.
Add After | Add a child element, comment, or processing instruction that can go after the item you have selected. For example, if you have a parent element called CD Collections that can contain an unlimited amount of children called CD, you could click a CD element and click | , as a CD element can go after another CD element.
Replace With | Replace one item with another. This option is not available if you turn grammar constraints off or if there are no valid alternatives for you to replace the item with. |
Any changes you make in the Design view are also reflected in the Source view and the Outline view.