Using Code Completion in XML Documents Constrained by a Single XML Schema

See Also

You can use code completion in XML files if the XML document is constrained by an XML schema. In the XML instance document, this constraint is represented by a xsi:schemaLocation or a xsi:noNamespaceSchemaLocation attribute in the root element of the schema. Typically, xsi:schemaLocation is used for schemas with a target namespace and xsi:noNamespaceSchemaLocation is used for schemas with no target namespace.

To create an XML document constrained by an XML schema and invoke code completion:

  1. From the main menu, choose File > New File.
    The New File wizard opens.
  2. Under Categories, select the XML node and under File Types, select the XML Document node, then click Next.
  3. Specify a name and location for the document and click Next.
  4. Select the XML Schema-Constrained Document radio button and click Next.
  5. Click the Browse button next to the Schema URI field to navigate to and select the schema file that will constrain the XML instance document.
    When you have selected the schema file, the IDE fills in the Document Namespace and Root Element fields. If the schema has no target namespace, the Document Namespace field is blank.
  6. If the schema has more than one root element, select the element you want to use for the constraint from the Root Element drop-down list.
  7. Click Finish.
    The IDE adds a node for the new .xml file in the Projects window, and the new file is open in the Source Editor.
  8. In the Source Editor tab of the XML document, position the cursor where you want to start adding content and type an opening left angle bracket (<).
    The code completion box opens. This box provides a scrolling list of schema elements. The list of elements is based on the XML schema file that constrains the current XML file.

To constrain an existing XML document by an XML schema and invoke code completion:

  1. Make a note of the following information from the schema file:
  2. Open the XML document in the Source Editor.
  3. In the XML document, replace the <root> tag with the following tag:
    <schema-root-element
      xmlns='schema-targetNamespace'
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
      xsi:schemaLocation='schema-targetNamespace path-to-schema/schema.xsd'>
    

    If the schema has no targetNamespace, use the following tag:
    <schema-root-element
      xmlns:prefix='schema-targetNamespace'
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
      xsi:noNamespaceSchemaLocation='path-to-schema/schema.xsd'>
    
  4. Replace the </root> tag with the following:
    </schema-root-element>
    
  5. Save your changes.
  6. In the Source Editor tab of the XML document, position the cursor where you want to start adding content and type an opening left angle bracket (<).
    The code completion box opens. This box provides a scrolling list of schema elements. The list of elements is based on the XML schema file that constrains the current XML file.
See Also
About Using Code Completion in XML Instance Documents Constrained by XML Schema
About XML Schema Tools

Legal Notices