# Xml / Dtd / Xsd

## Xml

Note

If you have xml files that do not have a .xml extension then eclipse may not recognize it as an xml file resulting in validation, completion, etc not working. Although the vim side may have the correct file type set, you may still need to add the file’s extension to the list of xml content types in the eclipse gui:

Preferences ‣ General ‣ Content Types ‣ Text ‣ XML

### Code Completion

Xml code completion uses the standard Vim code completion mechanism like so:

    <ser<Ctrl-X><Ctrl-U>

    <servlet>
      <ser<Ctrl-X><Ctrl-U>

    <servlet>
      <servlet-name>
    ...

Note

Requires a valid dtd or xsd to determine possible completions.

### Definition Lookup

When editing xml files, eclim provides a couple commands which allow you to quickly and easily open the file’s data definition and optionally jump to the definition of a particular element.

Note

When opening urls, these commands rely on netrw (:help netrw).

- :DtdDefinition [<element>] - When invoked, this command will attempt to locate the dtd declaration in the current xml file and open the dtd in a new split window. If you supply an element name when invoking the command, it will attempt to locate and jump to the definition of that element within the dtd. If no element name is supplied, but the cursor is located on an element name when invoke, that element name will be used.

- :XsdDefinition [<element>] - Behaves like :DtdDefinition except this command locates and opens the corresponding schema definition file.

### Validation

When editing a xml file eclim will default to validating the file when it is written. Any errors will be added to the current window’s location list (:help location-list) and their corresponding line number noted via Vim’s sign functionality.

If you don’t want xml files validated when saving them, you can set the g:EclimXmlValidate variable described in the configuration section below.

Regardless of whether you have validation enabled upon saving or not, the following command is still available for validating xml files on demand.

:Validate [<file>] - Validate the supplied file or the current file if no file name provided.

If eclimd is not currently running, and the xmllint command is available, eclim will validate the xml file using that. Eclim will never use xmllint when saving the file with g:EclimXmlValidate enabled.

### Format

On occasion you may encounter some xml content that is unformatted (like raw content from a web service).

    <blah><foo>one</foo><bar>two</bar></blah>

Executing :XmlFormat will reformat the current xml file like so:

    <blah>
      <foo>one</foo>
      <bar>two</bar>
    </blah>

### Configuration

Vim Settings

- g:EclimXmlValidate (Defualt: 1) - If set to 0, disables xml validation when saving the file.
- g:EclimValidateSortResults (Default: ‘occurrence’) - If set to ‘severity’, the validation results will be sorted by severity (errors > warnings > info > etc.)

## Dtd

### Validation

When editing a dtd file eclim will default to validating the file when it is written. Any errors will be added to the current window’s location list (:help location-list) and their corresponding line number noted via Vim’s sign functionality.

If you do not want your dtd files validated automatically when saved, you can set the g:EclimDtdValidate variable described in the configuration section below.

Whether or not auto validation has been enabled, eclim also exposes the command :Validate to manually execute the validation of the file.

### Configuration

Vim Settings

- g:EclimDtdValidate (Default: 1) - If set to 0, disables validation when saving the file.
- g:EclimValidateSortResults (Default: ‘occurrence’) - If set to ‘severity’, the validation results will be sorted by severity (errors > warnings > info > etc.)

## Xsd

### Validation

When editing a xsd file eclim will default to validating the file when it is written. Any errors will be added to the current window’s location list (:help location-list) and their corresponding line number noted via Vim’s sign functionality.

If you do not want your xsd files validated automatically when saved, you can set the g:EclimXsdValidate variable described in the configuration section below.

Whether or not auto validation has been enabled, eclim also exposes the command :Validate to manually execute the validation of the file.

### Configuration

Vim Settings

- g:EclimXsdValidate (Default: 1) - If set to 0, disables validation when saving the file.
- g:EclimValidateSortResults (Default: ‘occurrence’) - If set to ‘severity’, the validation results will be sorted by severity (errors > warnings > info > etc.)