redhat-developer / vscode-xml

Editing XML in Visual Studio Code made easy
Eclipse Public License 2.0
254 stars 78 forks source link

Allow wildcards for systemId #119

Open kozubikmichal opened 5 years ago

kozubikmichal commented 5 years ago

Hi colleagues,

do you plan to allow wildcards for specifying schemas path? So one can use

 "xml.fileAssociations": [{
        "systemId": "./schemas/*.xsd",
        "pattern": "**/*.xml"
    }]

Michal

angelozerr commented 5 years ago

@kozubikmichal I don't understand very good your idea. If you have those files:

foo.xml must be validated by which xsd file?

kozubikmichal commented 5 years ago

Hi @angelozerr ideally by both if you specify the regex in this way. My use case - we're using UI5 framework. This comes with several xsd files, one per library (or module if you want). For example WebStorm can analyze all of this xsd files and does the analysis automatically. But for the VSCode I'm not able to make it work.

Regards Michal

benfontan commented 5 years ago

I have the same usecase than @kozubikmichal. Basically what we need is the capacity to associate a specific namespace (xmlns) to a xsd, not a file pattern.

angelozerr commented 4 years ago

ideally by both if you specify the regex in this way.

Not sure that it's possible.

My use case - we're using UI5 framework. This comes with several xsd files, one per library (or module if you want). For example WebStorm can analyze all of this xsd files and does the analysis automatically. But for the VSCode I'm not able to make it work.

Could you share please a simple sample. Thanks!

I have the same usecase than @kozubikmichal. Basically what we need is the capacity to associate a specific namespace (xmlns) to a xsd, not a file pattern.

XML catalog is done for that. have you tried it?

angelozerr commented 4 years ago

@kozubikmichal I have the impression that your need is to map XML file name with XSD file name, no? If systemId will able to use {0} (but without *) like this :

"xml.fileAssociations": [{
       "systemId": "./schemas/{0}.xsd",
       "pattern": "**/{0}.xml"
   }]

Do you think you could use it for your usecase?

kozubikmichal commented 4 years ago

@angelozerr No, this would not fit for the SAP UI5 usecase. Here is the example of the valid UI5 XML Fragment definition:

<core:FragmentDefinition
    xmlns="sap.m"
    xmlns:core="sap.ui.core">
   <Text text="Hello World"/>
   <core:Icon src="sap-icon://accept" />
</core:FragmentDefinition>

Here you can see 2 different xml namespaces where each has its own xsd definition:

For this I need the xml file to be validated against both of them. Of course there might be more namespaces used.

Regards Michal

angelozerr commented 4 years ago

@kozubikmichal I didn't know that you could use namespace. In this case it's possible to do that with XML catalog.

The basic idea is to write a XML catalog like this:

<?xml version="1.0"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
  <uri name="sap.m" uri="https://openui5.hana.ondemand.com/downloads/schemas/sap.m.xsd" />
  <uri name="sap.ui.core" uri="https://openui5.hana.ondemand.com/downloads/schemas/sap.ui.core.xsd" />
  <uri name="sap.ui.unified" uri="https://openui5.hana.ondemand.com/downloads/schemas/sap.ui.unified.xsd" />
  <uri name="sap.ui.layout" uri="https://openui5.hana.ondemand.com/downloads/schemas/sap.ui.layout.xsd" />
</catalog>

and reference it in the vscode settings:

{
    "xml.catalogs": [
        "./catalog.xml"
    ]
}

See the zip attached

vscode-xml-catalog-sapui.zip

But it seems that there are some troubles with validation (with src-resolve):

image

It's an another issue that we need to investigate.