0

Sometimes I find that GeoServer SLD files fail to validate, even when copying code directly from the SLD Cookbook.

For example, I start with the polygon with styled label sample code, paste it into a new GeoServer style, validate it, and confirm that everything is fine.

Next I try to add the label halo code:

<Halo>
  <Radius>3</Radius>
  <Fill>
    <CssParameter name="fill">#FFFFFF</CssParameter>
  </Fill>
</Halo>

I can see that the halo is located just before the closing </TextSymbolizer> in the SLD Cookbook example, so I paste it just before the </TextSymbolizer> in my style:

  <Fill>
    <CssParameter name="fill">#000000</CssParameter>
  </Fill>
  <Halo>
    <Radius>3</Radius>
    <Fill>
      <CssParameter name="fill">#FFFFFF</CssParameter> 
    </Fill>
  </Halo>
</TextSymbolizer>

This now fails to validate with the message:

line 41: cvc-complex-type.2.4.a: Invalid content was found starting with element 'Halo'. One of '{"http://www.opengis.net/sld":VendorOption}' is expected.

This error message doesn't really help me. What is the cause of this problem and how can it be rectified?

2

I stumbled across the answer to this (I can't see it explicitly listed in the GeoServer documentation) so I'm posting it here in case it helps others.

Ian Turton mentions in this answer that:

XML is ordered (at least in the SLD schema) so you must use the elements in the right order

Examining the SLD schema and searching for the keyword halo, it's apparent that the halo must be specified before the fill:

<xsd:element ref="sld:Halo" minOccurs="0"/>
<xsd:element ref="sld:Fill" minOccurs="0"/>

Re-ordering the elements in my SLD to match this pattern resolves the problem.

The key point is that, as Ian mentions, the order of elements in a GeoServer SLD file is important.

  • 3
    SLD is an OGC standard and requirement of correctly ordered elements is set there, not by GeoServer. – user30184 Jun 12 '18 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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