Skip to content

Commit 18b846f

Browse files
committed
Separate instructions for testing well formed XML files and validation
against DTD Fixes #947 Signed-off-by: azerr <[email protected]>
1 parent e08f378 commit 18b846f

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

docs/Commands.md

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ This command re-triggers the [XML Validation](Validation.md#xml-validation) for
2020

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

23+
## Revalidate current XML file (XML Syntax Only)
24+
25+
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.
26+
27+
When the [Server Cache Path](Preferences.md#server-cache-path) is activated, the command removes the referenced XSD, DTD grammar from the local cache.
28+
2329
## Revalidate all open XML files
2430

2531
This command re-triggers the [XML Validation](Validation.md#xml-validation) for the all opened XML files.

docs/Validation.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,14 @@ Now, update the xsi:schemaLocation with bad location hint
518518

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

521+
## xml.validation.dtd.enabled
522+
523+
The `xml.validation.dtd.enabled` gives the capability to enable / disable the validation based on DTD. It can be configured with 3 values:
524+
525+
* `always`: enable DTD based validation.
526+
* `never`: disable DTD based validation.
527+
* `onValidDTD`: enable DTD based validation only when the declared DOCTYPE is valid.
528+
521529
## xml.validation.filters
522530

523531
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`:
@@ -554,7 +562,7 @@ By default, vscode-xml uses this default validation filter:
554562
"noGrammar": "ignore",
555563
"schema": {
556564
"enabled": "never"
557-
}
565+
}
558566
},
559567
// Ignore no grammar hint for Eclipse files like .project
560568
{

package.json

+25
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,22 @@
506506
"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.",
507507
"scope": "window"
508508
},
509+
"xml.validation.dtd.enabled": {
510+
"type": "string",
511+
"default": "always",
512+
"enum": [
513+
"always",
514+
"never",
515+
"onValidDTD"
516+
],
517+
"markdownEnumDescriptions": [
518+
"Enable DTD based validation.",
519+
"Disable DTD based validation.",
520+
"Enable DTD based validation only when the declared DOCTYPE is valid for the root element."
521+
],
522+
"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.",
523+
"scope": "window"
524+
},
509525
"xml.validation.disallowDocTypeDecl": {
510526
"type": "boolean",
511527
"default": false,
@@ -765,6 +781,11 @@
765781
"title": "Revalidate current XML file",
766782
"category": "XML"
767783
},
784+
{
785+
"command": "xml.validation.syntax.current.file",
786+
"title": "Revalidate (Only syntax) current XML file",
787+
"category": "XML"
788+
},
768789
{
769790
"command": "xml.validation.all.files",
770791
"title": "Revalidate all opened XML files",
@@ -802,6 +823,10 @@
802823
"command": "xml.validation.current.file",
803824
"when": "editorLangId in xml.supportedLanguageIds && XMLLSReady"
804825
},
826+
{
827+
"command": "xml.validation.syntax.current.file",
828+
"when": "editorLangId == xml && XMLLSReady"
829+
},
805830
{
806831
"command": "xml.validation.all.files",
807832
"when": "XMLLSReady"

src/commands/clientCommandConstants.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export const OPEN_DOCS = 'xml.open.docs';
4343
*/
4444
export const VALIDATE_CURRENT_FILE = 'xml.validation.current.file';
4545

46+
export const VALIDATE_ONLY_SYNTAX_CURRENT_FILE = 'xml.validation.syntax.current.file';
47+
4648
export const VALIDATE_ALL_FILES = 'xml.validation.all.files';
4749

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

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

77-
export const REFACTOR_SURROUND_WITH_CDATA = 'xml.refactor.surround.with.cdata';
79+
export const REFACTOR_SURROUND_WITH_CDATA = 'xml.refactor.surround.with.cdata';

src/commands/registerCommands.ts

+21
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,27 @@ function registerValidationCommands(context: ExtensionContext) {
141141
window.showErrorMessage('Error during XML validation ' + error.message);
142142
});
143143
}));
144+
145+
// Revalidate (Only XML syntax) current file
146+
context.subscriptions.push(commands.registerCommand(ClientCommandConstants.VALIDATE_ONLY_SYNTAX_CURRENT_FILE, async (identifierParam, validationArgs) => {
147+
let identifier = identifierParam;
148+
if (!identifier) {
149+
const uri = window.activeTextEditor.document.uri;
150+
identifier = TextDocumentIdentifier.create(uri.toString());
151+
}
152+
const configXML = workspace.getConfiguration().get('xml.validation');
153+
const x = JSON.stringify(configXML); //configXML is not a JSON type
154+
const validationSettings = JSON.parse(x);
155+
validationSettings['dtd']['enabled'] = 'never';
156+
validationSettings['schema']['enabled'] = 'never';
157+
commands.executeCommand(ClientCommandConstants.EXECUTE_WORKSPACE_COMMAND, ServerCommandConstants.VALIDATE_CURRENT_FILE, identifier, validationArgs, validationSettings).
158+
then(() => {
159+
window.showInformationMessage('The current XML file was successfully validated (XML Syntax Only).');
160+
}, error => {
161+
window.showErrorMessage('Error during XML validation (XML Syntax Only) ' + error.message);
162+
});
163+
}));
164+
144165
// Revalidate all open files
145166
context.subscriptions.push(commands.registerCommand(ClientCommandConstants.VALIDATE_ALL_FILES, async () => {
146167
commands.executeCommand(ClientCommandConstants.EXECUTE_WORKSPACE_COMMAND, ServerCommandConstants.VALIDATE_ALL_FILES).

0 commit comments

Comments
 (0)