# 引用 XML 模式和 DTD

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/zh-cn/help/idea/llms.txt).

您的 XML 文件可能引用外部 XML schema（XSD）或 DTD 文件，例如：

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

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

或

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

如果引用的 URL 或命名空间 URI 未被识别，则会被标记为错误。 要解决这个问题：

Procedure:

1. 将文本光标放置在引用的 URL，并按 `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Alt+Enter` (NetBeans), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS))。

![引用一个不熟悉的 URL](https://resources.jetbrains.com/help/img/idea/2026.3/reference-nonexist-url-xml.png)

2. 从建议选项列表中，选择以下之一：

* 获取外部资源 . IntelliJ IDEA 下载了引用的文件并将其与 URL （或命名空间 URI）关联。 错误高亮消失。 XML 文件根据下载的模式或 DTD 进行验证。 （这些 URL 和命名空间 URI 与架构和 DTD 文件的关联显示在 设置 对话框中的 [Schemas and DTDs 页](settings-languages-schemas-and-dtds.html)。）

* 手动设置外部资源 . 当您已有合适的 schema 或 DTD 文件本地可用时，使用此选项。 映射外部资源 对话框将打开，您将能够为指定的 URL 或命名空间 URI 选择文件（例如， `http://www.example.org/xsds/example.xsd` 或 `http://www.example.org` ）。 操作结果与获取资源的情况相同。

* 忽略外部资源 . 已将 URL 或命名空间 URI 添加到忽略模式和 DTD 的列表中。 （此列表显示在 设置 对话框中的 [架构和 DTD 页面](settings-languages-schemas-and-dtds.html) 上。）错误高亮消失。 IntelliJ IDEA 不会验证 XML 文件，然而，它会检查 XML 文件是否格式良好。

* 为外部资源添加 Xsi 架构位置 . 此意图操作可让您完成根 XML 元素。 如果已指定命名空间，IntelliJ IDEA 可以添加一些缺失的属性。

例如，如果您有一个片段如下：

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

您调用   为外部资源添加 Xsi 架构位置   意图操作后  `xmlns`  属性的值，结果将是：

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

在此步骤中，您可以添加模式 URL，然后将 URL（或命名空间 URI）映射到适当的模式文件，或将 URL（或 URI）添加到忽略的模式和 DTD 列表中。

## See also

### 过程

[生成 DTD](generating-dtd.html) [从实例文档生成 XML 模式](generating-xml-schema-from-instance-document.html)

### 参考

[架构和 DTD](settings-languages-schemas-and-dtds.html)

