XML schema validation

Hi

It would be very nice if the schema for various Enonic XP XML files where available so I can validate them…

While developing I very quickly run into these types of error messages:

ERROR c.e.x.j.i.e.JsonExceptionMapper - XmlException
com.enonic.xp.xml.XmlException: null

So basically I forgot or wrote something wrong in the XML file.
But finding that something might take a long time.

If I could simply run the file through a validator it would immediately tell me where I borked it.

1 Like

I agree. Adding more validation (both schema, required files, etc) to the build process would help a lot.

+1, I always tend to have the docs open whenever I write content types or configs.

We have actually XSD’s for everything. We do not yet validate against it, but this is planned for the future. If you want to use the XSD for validation in your IDE, you can either point to the XSD from a Jar file or copy the XSD to a desired location.

Here’s our schemas:

To validate against the XSD’s you will need to have the right namespace. Right now it will work for no namespaces also. Here’s an example of using the namespace:

<content-type xmlns="urn:enonic:xp:model:1.0">
  ...
</content-type>

In some IDE’s, like IntelliJ, you can then just associate this namespace with an XSD inside a jar in your project. This jar is already in your project if you are using any of our libs. Else, you can add the following to your dependency list:

compile 'com.enonic.xp:core-api:6.4.0'

If not you can associate it using xsi:schemaLocation:

<content-type 
    xmlns="urn:enonic:xp:model:1.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:enonic:xp:model:1.0 path/to/model.xsd">
  ...
</content-type>

This path/to/model.xsd is the physical location of the XSD on your file system. If you want, you could just point it to the XSD on GitHub by using the following URL https://raw.githubusercontent.com/enonic/xp/master/modules/core/core-api/src/main/resources/META-INF/xsd/model.xsd. Or for a specified tag: https://raw.githubusercontent.com/enonic/xp/v6.4.1/modules/core/core-api/src/main/resources/META-INF/xsd/model.xsd.

Hope this helps.

5 Likes