Walkthrough: Use XML editor features
The steps in this walkthrough show you how to create a new XML document. The walkthrough also uses some of the features of the XML Editor that make it valuable for XML authoring.
Before starting the walkthrough, save the hireDate.xsd file (included below in this topic) to your local computer.
To create a new XML file and associate it with an XML schema
On the File menu, point to New, and click File.
Select XML File in the Templates pane and click Open.
A new file is opened in the editor. The file contains a default XML declaration,
<?xml version="1.0" encoding="utf-8">.
In the document properties window, click the browse button (...) on the Schemas field.
The XSD Schemas dialog box is displayed.
The Open XSD Schema dialog box is displayed.
Select the hireDate.xsd file and click Open.
The XML Schema is now associated with the XML document. The XML Schema is used to validate the document. It is also used by IntelliSense to populate the member list of valid elements.
To add data
<in the editor pane.
The members list displays the possible items:
!-- to add a comment.
!DOCTYPE to add a document type.
? to add a processing instruction.
employee to add the root element.
Select <!-- to add a comment node and press Enter.
The editor inserts a comment end tag and places the cursor between the start and end comment tags.
Type in Test XML file.
On a new line, type
<, and select employee from the member list.
The editor adds the start of an XML element,
<employee. At this point you can add attributes to the element or you can close the start tag by typing
>to close the tag.
The editor adds the end tag. The end tag is added with a wavy underline indicating a validation error. The ToolTip displays the message: The element 'employee' has incomplete content. Expected 'ID'.
<and select ID from the member list. Then type
The editor adds the XML element,
<ID></ID>, and positions the cursor after the ID start tag.
The abc text has a wavy underline. The ToolTip displays the message: The 'ID' element has an invalid value according to its data type.
Right-click on the ID element and select Go To Definition.
The editor opens the hireDate.xsd file in a new document window and positions the cursor on the ID schema element definition.
Return to the XML file, and replace the abc text with 123.
The wavy underline and ToolTip are cleared under the ID element value. The ToolTip for the employee end tag now displays the message: The element 'employee' has incomplete content. Expected 'hire-date'.
Place the cursor after the ID end tag, type in
<, select hire-date from the member list, and then type in
The editor adds the XML element,
<hire-date></hire-date>, and positions the cursor after the hire-date start tag.
Type in 2003-01-10 for the hire-date value.
To format the XML document
Select the Format Document button from the XML Editor toolbar.
The XML document is reformatted.
To save the XML document
From the File menu, select Save As.
The Save File As dialog box is displayed. The default filename is 'XMLFile1'.
Enter the file name and location for the XML document and click Save.
The following schema file is used by the walkthrough.
<?xml version="1.0"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:empl-hire" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="employee"> <xs:complexType> <xs:sequence> <xs:element name="ID" type="xs:unsignedShort" /> <xs:element name="hire-date" type="xs:date" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>