{"id":13223,"library":"geostyler-sld-parser","title":"GeoStyler SLD Parser","description":"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.","status":"active","version":"8.4.2","language":"javascript","source_language":"en","source_url":"https://github.com/geostyler/geostyler-sld-parser","tags":["javascript","geostyler","parser","style","sld","typescript"],"install":[{"cmd":"npm install geostyler-sld-parser","lang":"bash","label":"npm"},{"cmd":"yarn add geostyler-sld-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add geostyler-sld-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency providing the abstract style object model that this parser converts to and from.","package":"geostyler-style","optional":false}],"imports":[{"note":"The library primarily uses ES Module syntax. Direct CommonJS `require` for the default export will lead to issues. For Node.js, ensure your environment supports ESM or use dynamic `import()`.","wrong":"const SLDParser = require('geostyler-sld-parser');","symbol":"SLDParser","correct":"import SLDParser from 'geostyler-sld-parser';"},{"note":"The `Style` type definition, fundamental for interacting with GeoStyler parsers, comes from the `geostyler-style` package, not `geostyler-sld-parser` directly.","wrong":"import { Style } from 'geostyler-sld-parser';","symbol":"Style","correct":"import { Style } from 'geostyler-style';"},{"note":"While the default export `SLDParser` is common, `SldStyleParser` can also be imported as a named export. Both refer to the same class.","symbol":"SldStyleParser","correct":"import { SldStyleParser } from 'geostyler-sld-parser';"}],"quickstart":{"code":"import SLDParser from 'geostyler-sld-parser';\nimport { Style } from 'geostyler-style';\n\nconst pointSimplePoint = {\n  name: 'My Style',\n  rules: [\n    {\n      name: 'My Rule',\n      symbolizers: [\n        {\n          kind: 'Mark',\n          wellKnownName: 'circle',\n          color: '#FF0000',\n          radius: 6\n        }\n      ]\n    }\n  ]\n};\n\nconst parser = new SLDParser();\n\nconsole.log('--- Writing Style ---');\nparser\n  .writeStyle(pointSimplePoint)\n  .then(({output: sld}) => {\n    console.log('Generated SLD:');\n    console.log(sld);\n  })\n  .catch(error => console.error('Error writing style:', error));\n\n// Read style from string\nlet sldString = '<?xml version=\"1.0\" encoding=\"UTF-8\"?><sld:StyledLayerDescriptor xmlns=\"http://www.opengis.net/sld\" xmlns:sld=\"http://www.opengis.net/sld\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" version=\"1.0.0\"> <sld:NamedLayer> <sld:Name>Default Styler</sld:Name> <sld:UserStyle> <sld:Name>Default Styler</sld:Name> <sld:Title>Gravel_Program_2016</sld:Title> <sld:FeatureTypeStyle> <sld:Name>name</sld:Name> <sld:Rule> <sld:MinScaleDenominator>1.0</sld:MinScaleDenominator> <sld:MaxScaleDenominator>1.0E7</sld:MaxScaleDenominator> <sld:LineSymbolizer> <sld:Stroke> <sld:CssParameter name=\"stroke\">#8000FF</sld:CssParameter> <sld:CssParameter name=\"stroke-width\">3.000</sld:CssParameter> </sld:Stroke> </sld:LineSymbolizer> </sld:Rule> </sld:FeatureTypeStyle> </sld:UserStyle> </sld:NamedLayer> </sld:StyledLayerDescriptor>';\n\nconsole.log('\\n--- Reading Style ---');\nparser\n  .readStyle(sldString)\n  .then(({output: sldObject}) => {\n    console.log('Parsed GeoStyler Style Object:');\n    console.log(JSON.stringify(sldObject, null, 2));\n  })\n  .catch(error => console.error('Error reading style:', error));","lang":"typescript","description":"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`."},"warnings":[{"fix":"Upgrade your Node.js environment to version 20.6.0 or newer. Use `nvm install 20 && nvm use 20` or similar version management tools.","message":"The package requires Node.js version 20.6.0 or higher. Older Node.js versions will likely encounter compatibility issues or fail to run.","severity":"breaking","affected_versions":"<8.x.x"},{"fix":"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())`.","message":"When using `geostyler-sld-parser` in a CommonJS environment (e.g., older Node.js scripts), direct `require('geostyler-sld-parser')` will typically return an object containing the `default` export. Access the parser using `.default` (e.g., `new (require('geostyler-sld-parser')).default()`).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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.","message":"Version 8.0.1 explicitly fixed a build issue by enforcing `geostyler-style` version 10.2. This suggests that earlier versions of `geostyler-sld-parser` (specifically around 8.0.0) might have had compatibility problems with `geostyler-style` versions prior to 10.2.","severity":"breaking","affected_versions":"8.0.0"},{"fix":"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.","message":"SLD styling has many nuances, and not all SLD capabilities (especially complex vendor-specific extensions or very old SLD versions) might be fully supported by the parser. Review the generated or parsed style for accuracy if encountering unexpected results.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"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+.","cause":"Attempting to `new` a default export from a CommonJS `require()` call without accessing the `.default` property, or using an incompatible Node.js version.","error":"TypeError: SLDParser is not a constructor"},{"fix":"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`).","cause":"The `geostyler-style` peer dependency is missing or an incompatible version is installed.","error":"Error: Cannot find module 'geostyler-style'"},{"fix":"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.","cause":"The input SLD string is malformed XML, contains invalid characters, or is not a valid SLD document.","error":"XML parsing error: 'Unclosed tag' or 'Invalid character'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}