Using Code Completion in XML Documents Constrained by Multiple XML Schemas
See Also
You can constrain an XML instance document by more than one schema file if at least one of the schema files has an xsd:any or an 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 the 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
- Definition of xsd:any or xsd:anyAttribute.
The xsd:any (or xsd:anyAttribute) must exist in the root element of the base constraining schema. For example, assume the following:
- You are using A.xsd, B.xsd, and C.xsd to constrain instance.xml.
- The root element that you are using for the constraint is the root element of A.xsd, called A-Element.
In this case, the xsd:any (or xsd:anyAttribute) must be defined in A-Element to see the artifacts from A.xsd, B.xsd, and C.xsd in instance.xml.
- Selecting multiple files during XML instance document creation.
When you create an XML instance document in the IDE, you can only select one XML schema file to constrain that document. You must add the references to the other schema files using the Source Editor.
- Location of constraining schema files.
Make sure the schema files you want to use to constrain the XML instance document are available in your file system. In this release, the IDE does not allow you to reference external schema files for the purpose of constraining XML instance documents.
To create an XML document constrained by multiple XML schema files and invoke code completion:
- From the main menu, choose File > New File.
The New File wizard opens.
- Under Categories, select the XML node and under File Types, select the XML Document node, then click Next.
- Specify a name and location for the document and click Next.
- Select the XML Schema-Constrained Document radio button and click Next.
- 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.
- 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.
- 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.
- 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'
- Save your changes.
- 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.
- When you use wildcards and you select an element from another namespace, the IDE will automatically insert a namespace declaration for that element. The IDE will try different prefixes, starting with ns1, and if a match is found, a declaration is added as follows: xmlns:ns1="targetNamespace-of-selected-element".
- See Also
- About Using Code Completion in XML Instance Documents Constrained by XML Schema
- About XML Schema Tools
Legal Notices