eerohele / exalt

A Sublime Text plugin for validating and formatting XML documents
MIT License
22 stars 3 forks source link

Validating Magento 2 XML files #17

Closed churiart closed 5 years ago

churiart commented 5 years ago

I'm trying to make Exalt to work with Magento 2 xml files for validation. Its xml files could start with e.g.:

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">

and that urn points to schema.xsd file in (starting from root directory):

ROOT/vendor/Magento/framework/Setup/Declaration/Schema/etc/schema.xsd

I have generated a catalog file named misc.xml with the built in Magento command which contains:

<?xml version="1.0"?>
<project version="4">
  <component version="2" name="ProjectRootManager"/>
  <component name="ProjectResources">
    <resource url="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd" location="D:/path/to/Magento/vendor/magento/framework/Setup/Declaration/Schema/etc/schema.xsd"/>
    <resource url="urn:magento:framework:ObjectManager/etc/config.xsd" location="D:/path/to/Magento/vendor/magento/framework/ObjectManager/etc/config.xsd"/>
.
.
.

and gave it to Exalt:

{
    "xml_catalog_files": [
        "D:/path/to/Magento/misc.xml"
    ]
}

But Exalt throws error on not finding urn (Failed to locate the main schema resource...). Is there anyway to configure Exalt to understand the file path? Thanks

eerohele commented 5 years ago

Your misc.xml doesn't look like an OASIS XML catalog file, which is the only kind of catalog Exalt supports.

Can you try replacing misc.xml with an OASIS XML catalog? I think something like this should work:

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE catalog
  PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
         "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
  <uri
    name="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd"
    uri="ROOT/vendor/Magento/framework/Setup/Declaration/Schema/etc/schema.xsd"/>
</catalog>

It's been a while since I've worked with this stuff, though, so you might need to fiddle with that a bit.

churiart commented 5 years ago

Thank you I got it working:

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE catalog
  PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
         "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
    <uri name="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd" uri="file:///D:/path/to/installation/vendor/magento/framework/Setup/Declaration/Schema/etc/schema.xsd"/>
    <uri name="urn:magento:framework:ObjectManager/etc/config.xsd" uri="file:///D:/path/to/instllation/vendor/magento/framework/ObjectManager/etc/config.xsd"/>
    .
    .
    .
</catalog>
eerohele commented 5 years ago

By the way, I think you could also do something along these lines:

<rewriteURI uriStartString="urn:magento:framework:" rewritePrefix="file:///D:/path/to/installation/vendor/magento/framework/"/>

I didn't test, though.

churiart commented 5 years ago

The exact same statement worked great and saved tens of kilobytes! Thank you

eerohele commented 5 years ago

I'm nothing if not prudent when it comes to kilobytes.

Glad to hear it works!