Using Code Completion in XML Instance Documents Constrained by Multiple XML Schema Files

See Also

You can constrain an XML instance document by more than one schema file if at least one of the schema files has a xsd:any or a xsd:anyAttribute, known as wildcards. When using these wildcards, the IDE will limit the information in the code completion box by namespace. Both xsd:any and xsd:anyAttribute come with an optional namespace attribute. The following table shows how the IDE substitutes wildcards based on the namespace attribute value.

namespace value Substitution
##any Any element from any namespace.
##other Any element from other namespaces other than the targetNamespace.
##targetNamespace Any element from targetNamespace.
##local Any unqualified element (no namespace).
List of URIs Elements from the specified namespaces.

For example, assume you have the following:

<a:RootA xmlns:a="http://xml.netbeans.org/schema/A"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xml.netbeans.org/schema/A A.xsd
  http://xml.netbeans.org/schema/B B.xsd
  http://xml.netbeans.org/schema/C C.xsd">
  < (current cursor position)
</a:RootA>

In this example, RootA is one of the root elements defined in schema A.xsd. If RootA had a xsd:any child element, then at the cursor position you would see items appearing from various namespaces as per substitution rule shown in the table above. The same applies for xsd:anyAttribute.

Rules and Restrictions

To create an XML document constrained by multiple XML schema files 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 first 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, update the xsi:schemaLocation value to add the additional schema files.
    In the sample shown below, base-schema-targetNamespace is the target namespace of the schema you selected in step 5, and base-schema is the path to the .xsd file and the name of the file.
     xsi:schemaLocation='base-schema-targetNamespace base-schema
        second-schema-targetNamespace second-schema
        third-schema-targetNamespace third-schema'
    
  9. Save your changes.
  10. 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 files that constrain the current XML file.
See Also
About Using Code Completion in XML Instance Documents Constrained by XML Schema
About XML Schema Tools

Legal Notices