lemminx icon indicating copy to clipboard operation
lemminx copied to clipboard

[Question] URIResolverExtension and XML Validation

Open BoykoAlex opened this issue 4 years ago • 1 comments

My understanding of the validation in XML server for an XML file is that it is done within LSPSAXParser and all schema related errors (i.e. attribute present missing from the schema) reported by LSPSAXParser via LSPErrorReporterForXML...

How does the validation take advantage of URIResolverExtension... For example my URIResolverExtension resolves NS URI to a local file URL and then schema is loaded from the local file... I wasn't able to find yet how validation would account for schema loaded from a local file with a help of URI Resolver. Is it supported at all?

BoykoAlex avatar Jan 06 '21 00:01 BoykoAlex

My understanding of the validation in XML server for an XML file is that it is done within LSPSAXParser and all schema related errors (i.e. attribute present missing from the schema) reported by LSPSAXParser via LSPErrorReporterForXML...

Exactly!

How does the validation take advantage of URIResolverExtension... For example my URIResolverExtension resolves NS URI to a local file URL and then schema is loaded from the local file... I wasn't able to find yet how validation would account for schema loaded from a local file with a help of URI Resolver. Is it supported at all?

URIResolverExtension extends xerces XMLEntityResolver implementation and it is registered in URIResolverExtensionManager (which stores list of URIResolverExtension ) which extends too XMLEntityResolver .

When validation occurs, the URIResolverExtensionManager is set in SAX parser at https://github.com/eclipse/lemminx/blob/c1f855c3de281ecc7db36f908df51cbb60e9d50c/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/diagnostics/XMLValidator.java#L77

In otherwise it should call your URIResolverExtension#resolveEntity (which does nothing by default). Please note URIResolverExtension is used too for XML completion / hover based on XSD/DTD.

I wasn't able to find yet how validation would account for schema loaded from a local file with a help of URI Resolver. Is it supported at all?

You mean validate XML with a XSD from a local file, it should work. I don't know if my answer is enough, if you have some trouble please share your code.

angelozerr avatar Jan 06 '21 09:01 angelozerr