diff --git a/README.md b/README.md index abd1fe45..48e8b317 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,8 @@ The following settings are supported: * [`xml.codeLens.enabled`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/CodeLens.md): Enable/disable XML CodeLens. Default is `false`. * [`xml.preferences.showSchemaDocumentationType`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Preferences.md#documentation-type): Specifies the source of the XML schema documentation displayed on hover and completion. Default is `all`. * [`xml.validation.enabled`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Validation.md): Enable/disable all validation. Default is `true`. -* `xml.validation.schema`: Enable/disable schema based validation. Default is `true`. Ignored if `xml.validation.enabled` is set to `false` -* [`xml.validation.disallowDocTypeDecl`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Validation.md#disallow-doc-type-declarations): Enable/disable if a fatal error is thrown if the incoming document contains a DOCTYPE declaration. Default is `false`. + * [`xml.validation.schema.enabled`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Validation.md#xmlvalidationschemaenabled): Enable/disable schema based validation. Default is `always`. Ignored if [`xml.validation.enabled`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Validation.md) is set to `false`. + * [`xml.validation.disallowDocTypeDecl`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Validation.md#disallow-doc-type-declarations): Enable/disable if a fatal error is thrown if the incoming document contains a DOCTYPE declaration. Default is `false`. * [`xml.validation.resolveExternalEntities`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Validation.md#resolve-external-entities): Enable/disable resolve of external entities. Default is `false`. * [`xml.validation.noGrammar`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Preferences.md#grammar): The message severity when a document has no associated grammar. Defaults to `hint`. * [`xml.symbols.enabled`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Symbols.md#xmlsymbolsenabled): Enable/disable document symbols (Outline). Default is `true`. diff --git a/docs/Validation.md b/docs/Validation.md index 9ca08f9b..a89eda97 100644 --- a/docs/Validation.md +++ b/docs/Validation.md @@ -417,3 +417,66 @@ If `xml.validation.resolveExternalEntities` is set to `true` (default is `false` Demonstration of the different behaviour: ![When using the default settings, an external entity that has an XML element as its content will not produce a validation error when nested in an element that expects character content. If `xml.validation.resolveExternalEntities` is enabled, then an error will be produced](./images/Validation/ExternalEntityResolvingDemonstration.gif) + +## xml.validation.schema.enabled + +The `xml.validation.schema.enabled` gives the capability to enable / disable the validation based on XSD. It can be configured with 3 values: + + * `always`: enable schema based validation. + * `never`: disable schema based validation. + * `onValidSchema`: enable schema based validation only when the declared xsi:schemaLocation hint or xsi:noNamespaceSchemaLocation is valid for the root element. + +To understand the `onValidSchema` settings value, lets go through an example: + +Create the XML `foo.xml` file: + +```xml + + + + +``` + +Create the XSD `foo.xsd` file (in the same folder as foo.xml) : + +```xml + + + + + + + + + + +``` + +In the XML file, the `BAD_ELEMENT` is higlighted as an error. Update the xsi:schemaLocation with bad namespace hint + +```xml + +... + xsi:schemaLocation=" + http://bad-foo foo.xsd"> +... + +``` + +In `always` you will have error, in `onValidSchema` you will have none error. + +Now, update the xsi:schemaLocation with bad location hint + +```xml + +... + xsi:schemaLocation=" + http://foo bad-foo.xsd"> +... + +``` + +In `always` you will have error, in `onValidSchema` you will have none error. \ No newline at end of file diff --git a/package.json b/package.json index 7090b375..3a0b4707 100644 --- a/package.json +++ b/package.json @@ -248,7 +248,7 @@ "Ignore `xsi:schemaLocation` content formatting." ], "default": "none", - "markdownDescription": "Split `xsi:schemaLocation` content. Default is `none`. Please see [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatxsischemalocationsplit%22%7D%5D) for more information", + "markdownDescription": "Split `xsi:schemaLocation` content. Default is `none`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatxsischemalocationsplit%22%7D%5D) for more information", "scope": "window" }, "xml.format.splitAttributes": { @@ -298,7 +298,7 @@ "Documentation comes from the `xs:documentation` and `xs:appinfo` elements.", "Displays no documentation." ], - "markdownDescription": "Specifies the source of the XML schema documentation displayed on hover and completion. Default is `all`. Please see [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Preferences%22%2C%22section%22%3A%22documentation-type%22%7D%5D) for more information.", + "markdownDescription": "Specifies the source of the XML schema documentation displayed on hover and completion. Default is `all`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Preferences%22%2C%22section%22%3A%22documentation-type%22%7D%5D) for more information.", "scope": "window" }, "xml.validation.enabled": { @@ -307,10 +307,20 @@ "markdownDescription": "Enable/disable all validation. Default is `true`.", "scope": "window" }, - "xml.validation.schema": { - "type": "boolean", - "default": true, - "markdownDescription": "Enable/disable schema based validation. Default is `true`. Ignored if `#xml.validation.enabled#` is set to `false`", + "xml.validation.schema.enabled": { + "type": "string", + "default": "always", + "enum": [ + "always", + "never", + "onValidSchema" + ], + "markdownEnumDescriptions": [ + "Enable schema based validation.", + "Disable schema based validation.", + "Enable schema based validation only when the declared xsi:schemaLocation hint or xsi:noNamespaceSchemaLocation is valid for the root element." + ], + "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.disallowDocTypeDecl": { @@ -356,12 +366,12 @@ "xml.symbols.maxItemsComputed": { "type": "integer", "default": 5000, - "markdownDescription": "The maximum number of outline symbols and folding regions computed (limited for performance reasons). Default is `5000`. Please see [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Symbols%22%2C%22section%22%3A%22xmlsymbolsmaxitemscomputed%22%7D%5D) for more information." + "markdownDescription": "The maximum number of outline symbols and folding regions computed (limited for performance reasons). Default is `5000`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Symbols%22%2C%22section%22%3A%22xmlsymbolsmaxitemscomputed%22%7D%5D) for more information." }, "xml.symbols.showReferencedGrammars": { "type": "boolean", "default": true, - "markdownDescription": "Show referenced grammars in the Outline. Default is `true`. Please see [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Symbols%22%2C%22section%22%3A%22xmlsymbolsshowreferencedgrammars%22%7D%5D) for more information.", + "markdownDescription": "Show referenced grammars in the Outline. Default is `true`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Symbols%22%2C%22section%22%3A%22xmlsymbolsshowreferencedgrammars%22%7D%5D) for more information.", "scope": "window" }, "xml.symbols.filters": { @@ -405,7 +415,7 @@ "xml.extension.jars": { "type": "array", "default": [], - "markdownDescription": "An array of paths to JARs that should be contributed to the LemMinX classpath. The paths can include glob patterns. This is intended to be used as a tool for developing extensions to vscode-xml. Please see [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Preferences%22%2C%22section%22%3A%22extension-jars%22%7D%5D) for more information", + "markdownDescription": "An array of paths to JARs that should be contributed to the LemMinX classpath. The paths can include glob patterns. This is intended to be used as a tool for developing extensions to vscode-xml. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Preferences%22%2C%22section%22%3A%22extension-jars%22%7D%5D) for more information", "scope": "window" } }