MCPcopy Index your code
hub / github.com/MapServer/MapServer / msSLDParseSLD

Function msSLDParseSLD

mapogcsld.c:506–616  ·  view source on GitHub ↗

/ msSLDParseSLD */ / Parse the sld document into layers : for each named layer */ there is one mapserver layer created with approproate */ classes and styles. */ Returns an array of mapserver layers. The pnLayres if */ provided will indicate the size of the returned array. */ /

Source from the content-addressed store, hash-verified

504/* provided will indicate the size of the returned array. */
505/************************************************************************/
506layerObj *msSLDParseSLD(mapObj *map, char *psSLDXML, int *pnLayers)
507{
508 CPLXMLNode *psRoot = NULL;
509 CPLXMLNode *psSLD, *psNamedLayer, *psChild, *psName;
510 layerObj *pasLayers = NULL;
511 int iLayer = 0;
512 int nLayers = 0;
513
514
515 if (map == NULL || psSLDXML == NULL || strlen(psSLDXML) <= 0 ||
516 (strstr(psSLDXML, "StyledLayerDescriptor") == NULL))
517 {
518 msSetError(MS_WMSERR, "Invalid SLD document", "");
519 return NULL;
520 }
521
522 psRoot = CPLParseXMLString(psSLDXML);
523 if( psRoot == NULL)
524 {
525 msSetError(MS_WMSERR, "Invalid SLD document : %s", "", psSLDXML);
526 return NULL;
527 }
528
529 /* strip namespaces ogc and sld and gml */
530 CPLStripXMLNamespace(psRoot, "ogc", 1);
531 CPLStripXMLNamespace(psRoot, "sld", 1);
532 CPLStripXMLNamespace(psRoot, "gml", 1);
533 CPLStripXMLNamespace(psRoot, "se", 1);
534
535
536/* -------------------------------------------------------------------- */
537/* get the root element (Filter). */
538/* -------------------------------------------------------------------- */
539 psChild = psRoot;
540 psSLD = NULL;
541
542 while( psChild != NULL )
543 {
544 if (psChild->eType == CXT_Element &&
545 EQUAL(psChild->pszValue,"StyledLayerDescriptor"))
546 {
547 psSLD = psChild;
548 break;
549 }
550 else
551 psChild = psChild->psNext;
552 }
553
554 if (!psSLD)
555 {
556 msSetError(MS_WMSERR, "Invalid SLD document : %s", "", psSLDXML);
557 return NULL;
558 }
559
560/* -------------------------------------------------------------------- */
561/* Parse the named layers. */
562/* -------------------------------------------------------------------- */
563 psNamedLayer = CPLGetXMLNode(psSLD, "NamedLayer");

Callers 1

msSLDApplySLDFunction · 0.85

Calls 5

msSetErrorFunction · 0.85
strcasecmpFunction · 0.85
initLayerFunction · 0.85
msStrdupFunction · 0.85
msSLDParseNamedLayerFunction · 0.85

Tested by

no test coverage detected