6

Where I can find the QML specification which is used for storing symbology information in QGIS?

I tried to Google it - but got no result.

1 Answer 1

1

There's nothing complicated about qml files, there just simple plain text XML files.

If you load one into notepad you'll see the layout is fairly straight forward.

You have a

<qgis>...</qgis>

tag that lists the version that created it among other things

Within this tag you have a

<transparencyLevelInt>

tag that holds transparency level info, a

<rendererer>

tag which appears to be instructions to the QGis rendering engine on how to draw the styles, and then within that renderer you have layer specific style information.

In my case because I saved some styles used for a categorised data set, I have a

<categories>

tag listing individual

<category>

tags that describe each category, and a

<symbols>

tag that includes a collection of

<symbol>

tags describing each symbol in the style set.

Further down it looks like there are entries for the layers name, label visibility, editing types and column names for the attributes in a layer.

It's all very straight forward to read, you just need to know how to pull apart the XML in the language you've chosen to use to manipulate them.

There's even a DTD address listed in the file, so loading the file into a DTD aware editor such as oxygeneXML should only allow you to enter legal tags in a legal order, however when I tried to access the DTD the web address was not found so you may want to check that one out further.

Update Nov 2019

Apparently folks are still arguing about the DTD in my comments and in others. The DTD that defines what the XML "SHOULD" look like can be found here

https://raw.githubusercontent.com/qgis/QGIS/master/qgis.dtd

I've just checked the file and it's there, and a quick cursory glance over it looks like everything expected is present.

20
  • 3
    What you provide is not specification. I'm looking for document which describes all qml tags and their purposes, like OGC SLD standard.
    – drnextgis
    Sep 27, 2012 at 13:51
  • Please read the last paragraph in my reply, starting : 'There's even a DTD.....' the DTD in question is embeded in the first line of the XML file, in XML file terms the DTD IS the specification.
    – shawty
    Sep 27, 2012 at 13:58
  • 3
    Theres nothing complicated about a simple project file. But as you go deeper, you'll find the world of composers, labels and symbols, and it aint so easy anymore. There's no description or explanation you can use, just have to find out as you go. The DTD? Did you check the DTD? I get the answer- "The requested URL /qgis.dtd was not found on this server." You can check svn.osgeo.org/qgis/trunk/qgis/qgis.dtd but thats not very useful either.
    – Marty
    Sep 27, 2012 at 14:05
  • 3
    As for the DTD on the contrary, it's very useful : xmlfiles.com/dtd a correctly formed DTD will tell you what you can and cannot put in an XML file created using it, in most cases when using a good editor it will also tell you the data type and (In the case of visual studio) will even give intellisense to show the compound types under a tag. All that leaves you to do is a little bit of research as to what the tags and attributes hold, which in most cases is fairly self explanatory. Iv'e done it loads of times with different XML files.
    – shawty
    Sep 27, 2012 at 14:45
  • 1
    The svn.osgeo.org/qgis/trunk/qgis/qgis.dtd DTD does not appear to define a QML file. <!ELEMENT qgis (title, extent, projectlayers, mapunits) > appears to conflict with your statement that within a QGIS file you can have a <transparencyLevelInt> ~ you can't directly according to the DTD. Looking at github.com/anitagraser/QGIS-resources/blob/master/qgis2/… There is no edittypes defined at all. The DTD referenced in the example doesn't exist...
    – nmtoken
    Dec 17, 2016 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.