IntelliJ IDEA 2016.2 Help

Referencing XML Schemas and DTDs

Your XML file may reference an external XML schema (XSD) or DTD file, e.g.

<root xmlns="http://www.example.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org http://www.example.org/xsds/example.xsd">

or

<!DOCTYPE root SYSTEM "http://www.example.org/dtds/example.dtd">

If the referenced URL or the namespace URI is "unfamiliar", it's marked as an error.

For situations like this, IntelliJ IDEA provides the following intention actions:

  • Fetch External Resource. IntelliJ IDEA downloads the referenced file and associates it with the URL (or the namespace URI). The error highlighting disappears. The XML file is validated according to the downloaded schema or DTD. (The associations of the URLs and the namespace URIs with the schema and DTD files are shown on the Schemas and DTDs page in the Settings dialog.)
  • Manually Setup External Resource. Use this option when you already have an appropriate schema or DTD file available locally. The Map External Resource dialog will open and you'll be able to select the file for the specified URL or namespace URI. The result of the operation is the same as in the case of fetching the resource.
  • Ignore External Resource. The URL or the namespace URI is added to the Ignored Schemas and DTDs list. (This list is shown on the Schemas and DTDs page in the Settings dialog.) The error highlighting disappears. IntelliJ IDEA won't validate the XML file, however, it will check if the XML file is well-formed.

There is one more intention action that you may find useful: Add Xsi Schema Location for External Resource. This intention action lets you complete your root XML elements. If the namespace is already specified, IntelliJ IDEA can add a couple of missing attributes.

For example, if you have a fragment like this:

<root xmlns="http://www.example.org">

and perform the intention action on the value of the xmlns attribute, the result will be:

<root xmlns="http://www.example.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org >

At this step, you'll be able to add the schema URL, and then map the URL (or the namespace URI) onto an appropriate schema file, or add the URL (or the URI) to the Ignored Schemas and DTDs list.

See Also

Last modified: 23 November 2016