Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate instructions for testing well formed XML files and validation against DTD #950

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ This command re-triggers the [XML Validation](Validation.md#xml-validation) for

When the [Server Cache Path](Preferences.md#server-cache-path) is activated, the command removes the referenced XSD, DTD grammar from the local cache.

## Revalidate current XML file (XML Syntax Only)

This command re-triggers the [XML Validation](Validation.md#xml-validation) for the current file only for XML syntax even if XML is bound to a DTD, XML Schema, RelaxNG.

When the [Server Cache Path](Preferences.md#server-cache-path) is activated, the command removes the referenced XSD, DTD grammar from the local cache.

## Revalidate all open XML files

This command re-triggers the [XML Validation](Validation.md#xml-validation) for the all opened XML files.
Expand Down
10 changes: 9 additions & 1 deletion docs/Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,14 @@ Now, update the xsi:schemaLocation with bad location hint

In `always` you will have error, in `onValidSchema` you will have none error.

## xml.validation.dtd.enabled

The `xml.validation.dtd.enabled` gives the capability to enable / disable the validation based on DTD. It can be configured with 3 values:

* `always`: enable DTD based validation.
* `never`: disable DTD based validation.
* `onValidDTD`: enable DTD based validation only when the declared DOCTYPE is valid.

## xml.validation.filters

XML validation filter gives you the capability to define validation rules for files matching a given pattern. For instance if you wish to disable validation for all files which have the `*.myxml` file extension, you must declare this filter in the `settings.json`:
Expand Down Expand Up @@ -554,7 +562,7 @@ By default, vscode-xml uses this default validation filter:
"noGrammar": "ignore",
"schema": {
"enabled": "never"
}
}
},
// Ignore no grammar hint for Eclipse files like .project
{
Expand Down
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,22 @@
"markdownDescription": "Enable/disable schema based validation. Default is `always`. Ignored if `#xml.validation.enabled#` is set to `false`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Validation%22%2C%22section%22%3A%22xmlvalidationschemaenabled%22%7D%5D) for more information.",
"scope": "window"
},
"xml.validation.dtd.enabled": {
"type": "string",
"default": "always",
"enum": [
"always",
"never",
"onValidDTD"
],
"markdownEnumDescriptions": [
"Enable DTD based validation.",
"Disable DTD based validation.",
"Enable DTD based validation only when the declared DOCTYPE is valid for the root element."
],
"markdownDescription": "Enable/disable DTD based validation. Default is `always`. Ignored if `#xml.validation.enabled#` is set to `false`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Validation%22%2C%22section%22%3A%22xmlvalidationdtdenabled%22%7D%5D) for more information.",
"scope": "window"
},
"xml.validation.disallowDocTypeDecl": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -765,6 +781,11 @@
"title": "Revalidate current XML file",
"category": "XML"
},
{
"command": "xml.validation.syntax.current.file",
"title": "Revalidate current XML file (XML syntax Only)",
"category": "XML"
},
{
"command": "xml.validation.all.files",
"title": "Revalidate all opened XML files",
Expand Down Expand Up @@ -802,6 +823,10 @@
"command": "xml.validation.current.file",
"when": "editorLangId in xml.supportedLanguageIds && XMLLSReady"
},
{
"command": "xml.validation.syntax.current.file",
"when": "editorLangId == xml && XMLLSReady"
},
{
"command": "xml.validation.all.files",
"when": "XMLLSReady"
Expand Down
4 changes: 3 additions & 1 deletion src/commands/clientCommandConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const OPEN_DOCS = 'xml.open.docs';
*/
export const VALIDATE_CURRENT_FILE = 'xml.validation.current.file';

export const VALIDATE_ONLY_SYNTAX_CURRENT_FILE = 'xml.validation.syntax.current.file';

export const VALIDATE_ALL_FILES = 'xml.validation.all.files';

export const OPEN_DOCS_HOME = 'xml.open.docs.home';
Expand Down Expand Up @@ -74,4 +76,4 @@ export const EXECUTE_WORKSPACE_COMMAND = 'xml.workspace.executeCommand';

export const REFACTOR_SURROUND_WITH_COMMENTS = 'xml.refactor.surround.with.comments';

export const REFACTOR_SURROUND_WITH_CDATA = 'xml.refactor.surround.with.cdata';
export const REFACTOR_SURROUND_WITH_CDATA = 'xml.refactor.surround.with.cdata';
21 changes: 21 additions & 0 deletions src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,27 @@ function registerValidationCommands(context: ExtensionContext) {
window.showErrorMessage('Error during XML validation ' + error.message);
});
}));

// Revalidate (Only XML syntax) current file
context.subscriptions.push(commands.registerCommand(ClientCommandConstants.VALIDATE_ONLY_SYNTAX_CURRENT_FILE, async (identifierParam, validationArgs) => {
let identifier = identifierParam;
if (!identifier) {
const uri = window.activeTextEditor.document.uri;
identifier = TextDocumentIdentifier.create(uri.toString());
}
const configXML = workspace.getConfiguration().get('xml.validation');
const x = JSON.stringify(configXML); //configXML is not a JSON type
const validationSettings = JSON.parse(x);
validationSettings['dtd']['enabled'] = 'never';
validationSettings['schema']['enabled'] = 'never';
commands.executeCommand(ClientCommandConstants.EXECUTE_WORKSPACE_COMMAND, ServerCommandConstants.VALIDATE_CURRENT_FILE, identifier, validationArgs, validationSettings).
then(() => {
window.showInformationMessage('The current XML file was successfully validated (XML Syntax Only).');
}, error => {
window.showErrorMessage('Error during XML validation (XML Syntax Only) ' + error.message);
});
}));

// Revalidate all open files
context.subscriptions.push(commands.registerCommand(ClientCommandConstants.VALIDATE_ALL_FILES, async () => {
commands.executeCommand(ClientCommandConstants.EXECUTE_WORKSPACE_COMMAND, ServerCommandConstants.VALIDATE_ALL_FILES).
Expand Down
Loading