The `geostyler-sld-parser` package provides an implementation of a GeoStyler style parser for Styled Layer Descriptor (SLD) XML. It facilitates the conversion between the GeoStyler's internal, technology-agnostic style object model and OGC SLD XML documents. The current stable version is 8.4.2, with releases occurring frequently, often on a monthly or bi-monthly basis, indicating active development and maintenance. Its key differentiator is its role within the broader GeoStyler ecosystem, enabling seamless interoperability and transformation of styling information across various geospatial platforms and formats, using a unified API. This parser handles both reading SLD XML into a GeoStyler style object and writing a GeoStyler style object out to SLD XML, including complex features like filters, symbolizers, and vendor options.
npm install geostyler-sld-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate the SLDParser, convert a GeoStyler style object into an SLD XML string using `writeStyle`, and parse an existing SLD XML string back into a GeoStyler style object using `readStyle`.
Upgrade your Node.js environment to version 20.6.0 or newer. Use `nvm install 20 && nvm use 20` or similar version management tools.
For ES Modules, use `import SLDParser from 'geostyler-sld-parser';`. For CommonJS, use `const SLDParser = require('geostyler-sld-parser').default;` or dynamic imports `import('geostyler-sld-parser').then(mod => new mod.default())`.Ensure your project's `geostyler-style` dependency is at least version 10.2 when using `geostyler-sld-parser` v8.0.0 or later to avoid potential build or runtime issues.
Consult the GeoStyler and SLD specifications. Report specific parsing or writing discrepancies as issues on the `geostyler-sld-parser` GitHub repository with example SLD and desired GeoStyler style.
For CommonJS, use `const SLDParser = require('geostyler-sld-parser').default;`. For ESM, ensure `import SLDParser from 'geostyler-sld-parser';` and that your Node.js environment is configured for ESM or is version 20.6.0+.Install `geostyler-style` explicitly: `npm install geostyler-style` or `yarn add geostyler-style`. Verify that the installed version meets the `geostyler-sld-parser`'s compatibility requirements (e.g., `>=10.2.0`).
Validate the SLD XML string before passing it to `readStyle()`. Ensure it's well-formed, correctly encoded (UTF-8 recommended), and adheres to the SLD specification. Use an XML validator tool.