MapServer / MapServer-import

3 stars 2 forks source link

WFS should have possibility to use a default namespace #1875

Open tbonfort opened 12 years ago

tbonfort commented 12 years ago

Reporter: bartvde@osgis.nl Date: 2006/08/24 - 14:43

Currently all attributes are by default prefixed by ms. This causes e.g. trouble
when transforming GML into Shape using ogr2ogr, the attribute names become ms_XXXX.

We need the possibility to not use a prefix and use
http://mapserver.gis.umn.edu/mapserver as the default namespace.

I tried using "OWS_namespace_prefix" "" to get this behaviour but it does not
work as yet.

What this would mean is:
xmlns:="http://mapserver.gis.umn.edu/mapserver"
change to:
xmlns="http://mapserver.gis.umn.edu/mapserver"

<:AAA36> --> <AAA36>

I will use this bug to track the necessary changes.

Hopefully this could make it into 4.10.
tbonfort commented 12 years ago

Author: bartvde@osgis.nl Date: 2006/08/29 - 10:20

Adding Steve to the cc.

I will provide a patch which I have tested against the 4.8.4 sources.

I can imagine this is too tricky to incorporate in 4.10, but maybe for the next
release this could be considered.
tbonfort commented 12 years ago

Author: bartvde@osgis.nl Date: 2006/08/29 - 10:46

Patch against mapgml.c (revision 1.78.2.3):

--- mapgml.c    2006-08-29 10:10:55.000000000 +0200
+++ ../mapserver-4.8.4/mapgml.c 2006-08-17 10:50:03.000000000 +0200
@@ -227,7 +227,7 @@

   if(name) tag_name = name;

-  if(namespace && (strlen(namespace) > 0))
+  if(namespace)
     msIO_fprintf(stream, "%s<%s:%s>\n", tab, namespace, tag_name);
   else
     msIO_fprintf(stream, "%s<%s>\n", tab, tag_name);
@@ -239,7 +239,7 @@

   if(name) tag_name = name;

-  if(namespace && (strlen(namespace) > 0))
+  if(namespace)
     msIO_fprintf(stream, "%s</%s:%s>\n", tab, namespace, tag_name);
   else
     msIO_fprintf(stream, "%s</%s>\n", tab, tag_name);
@@ -1022,7 +1022,7 @@
   if(!stream || !item) return;
   if(!item->visible) return;

-  if(!namespace || (strlen(namespace) == 0)) add_namespace = MS_FALSE;
+  if(!namespace) add_namespace = MS_FALSE;

   if(item->encode == MS_TRUE)
     encoded_value = msEncodeHTMLEntities(value);
@@ -1480,7 +1480,7 @@
       /* set the layer name */
       /* value = msOWSLookupMetadata(&(lp->metadata), "OFG", "layername");
         if(!value) value = lp->name; */
-      if (wfs_namespace && (strlen(wfs_namespace) > 0)) {
+      if (wfs_namespace) {
        layerName = (char *) malloc(strlen(wfs_namespace)+strlen(lp->name)+2);
        sprintf(layerName, "%s:%s", wfs_namespace, lp->name);
       } else {
tbonfort commented 12 years ago

Author: bartvde@osgis.nl Date: 2006/08/29 - 10:57

Patch against mapwfs.c (revision 1.73.2.1):

--- mapwfs.c    2006-08-29 09:57:07.000000000 +0200
+++ ../mapserver-4.8.4/mapwfs.c 2006-03-05 21:54:52.000000000 +0100
@@ -535,28 +535,28 @@
   if(!stream || !tab) return;

   if(!geometryList || geometryList->numgeometries == 0) { /* write a default
container */
-    msIO_fprintf(stream, "%s<xsd:element name=\"%s\"
type=\"gml:GeometryPropertyType\" minOccurs=\"0\" maxOccurs=\"1\"/>\n", tab,
OWS_GML_DEFAULT_GEOMETRY_NAME);
+    msIO_fprintf(stream, "%s<element name=\"%s\"
type=\"gml:GeometryPropertyType\" minOccurs=\"0\" maxOccurs=\"1\"/>\n", tab,
OWS_GML_DEFAULT_GEOMETRY_NAME);
     return;
   } else {
     if(geometryList->numgeometries == 1) {
       geometry = &(geometryList->geometries[0]);
-      msIO_fprintf(stream, "%s<xsd:element name=\"%s\" type=\"gml:%s\"
minOccurs=\"%d\"", tab, geometry->name, msWFSGetGeometryType(geometry->type,
outputformat), geometry->occurmin);
+      msIO_fprintf(stream, "%s<element name=\"%s\" type=\"gml:%s\"
minOccurs=\"%d\"", tab, geometry->name, msWFSGetGeometryType(geometry->type,
outputformat), geometry->occurmin);
       if(geometry->occurmax == OWS_GML_OCCUR_UNBOUNDED)
    msIO_fprintf(stream, " maxOccurs=\"UNBOUNDED\"/>\n");
       else
    msIO_fprintf(stream, " maxOccurs=\"%d\"/>\n", geometry->occurmax);
     } else {
-      msIO_fprintf(stream, "%s<xsd:choice>\n", tab);
+      msIO_fprintf(stream, "%s<choice>\n", tab);
       for(i=0; i<geometryList->numgeometries; i++) {
    geometry = &(geometryList->geometries[i]);

-   msIO_fprintf(stream, "  %s<xsd:element name=\"%s\" type=\"gml:%s\"
minOccurs=\"%d\"", tab, geometry->name, msWFSGetGeometryType(geometry->type,
outputformat), geometry->occurmin);
+   msIO_fprintf(stream, "  %s<element name=\"%s\" type=\"gml:%s\"
minOccurs=\"%d\"", tab, geometry->name, msWFSGetGeometryType(geometry->type,
outputformat), geometry->occurmin);
    if(geometry->occurmax == OWS_GML_OCCUR_UNBOUNDED)
      msIO_fprintf(stream, " maxOccurs=\"UNBOUNDED\"/>\n");
    else
      msIO_fprintf(stream, " maxOccurs=\"%d\"/>\n", geometry->occurmax);    
       }
-      msIO_fprintf(stream, "%s</xsd:choice>\n", tab);
+      msIO_fprintf(stream, "%s</choice>\n", tab);
     }
   }

@@ -579,7 +579,7 @@
   if(item->type)
     element_type = item->type;

-  msIO_fprintf(stream, "%s<xsd:element name=\"%s\" type=\"xsd:%s\"/>\n", tab,
element_name, element_type);
+  msIO_fprintf(stream, "%s<element name=\"%s\" type=\"%s\"/>\n", tab,
element_name, element_type);

   return;
 }
@@ -593,7 +593,7 @@
   if(constant->type)
     element_type = constant->type;

-  msIO_fprintf(stream, "%s<xsd:element name=\"%s\" type=\"xsd:%s\"/>\n", tab,
constant->name, element_type);
+  msIO_fprintf(stream, "%s<element name=\"%s\" type=\"%s\"/>\n", tab,
constant->name, element_type);

   return;
 }
@@ -612,14 +612,14 @@
   sprintf(element_tab, "%s      ", tab);

   if(group->type) {
-    msIO_fprintf(stream, "%s<xsd:element name=\"%s\" type=\"xsd:%s\">\n", tab,
group->name, group->type);
-    msIO_fprintf(stream, "%s  <xsd:complexType name=\"%s\">\n", tab, group->type);
+    msIO_fprintf(stream, "%s<element name=\"%s\" type=\"%s\">\n", tab,
group->name, group->type);
+    msIO_fprintf(stream, "%s  <complexType name=\"%s\">\n", tab, group->type);
   } else {
-    msIO_fprintf(stream, "%s<xsd:element name=\"%s\" type=\"%sType\">\n", tab,
group->name, group->name);     
-    msIO_fprintf(stream, "%s  <xsd:complexType name=\"%sType\">\n", tab,
group->name);
+    msIO_fprintf(stream, "%s<element name=\"%s\" type=\"%sType\">\n", tab,
group->name, group->name);     
+    msIO_fprintf(stream, "%s  <complexType name=\"%sType\">\n", tab, group->name);
   }

-  msIO_fprintf(stream, "%s    <xsd:sequence>\n", tab);
+  msIO_fprintf(stream, "%s    <sequence>\n", tab);

   /* now the items/constants (e.g. elements) in the group */ 
   for(i=0; i<group->numitems; i++) {
@@ -640,9 +640,9 @@
     }
   }

-  msIO_fprintf(stream, "%s    </xsd:sequence>\n", tab);
-  msIO_fprintf(stream, "%s  </xsd:complexType>\n", tab);
-  msIO_fprintf(stream, "%s</xsd:element>\n", tab);
+  msIO_fprintf(stream, "%s    </sequence>\n", tab);
+  msIO_fprintf(stream, "%s  </complexType>\n", tab);
+  msIO_fprintf(stream, "%s</element>\n", tab);

   return;
 }
@@ -733,21 +733,22 @@
   if(user_namespace_prefix != NULL && msIsXMLTagValid(user_namespace_prefix) ==
MS_FALSE)
     msIO_printf("<!-- WARNING: The value '%s' is not valid XML namespace.
-->\n", user_namespace_prefix);

-  msIO_printf("<xsd:schema\n"
+  msIO_printf("<schema\n"
        "   targetNamespace=\"%s\" \n"
-       "   xmlns=\"%s\" \n"
+       "   xmlns:%s=\"%s\" \n"
        "   xmlns:ogc=\"http://www.opengis.net/ogc\"\n"
        "   xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"
+       "   xmlns=\"http://www.w3.org/2001/XMLSchema\"\n"
        "   xmlns:gml=\"http://www.opengis.net/gml\"\n"
        "   elementFormDefault=\"qualified\" version=\"0.1\" >\n", 
-       user_namespace_uri_encoded, user_namespace_uri_encoded);
+       user_namespace_uri_encoded, user_namespace_prefix,  user_namespace_uri_encoded);

   encoded = msEncodeHTMLEntities( msOWSGetSchemasLocation(map) );
   if(outputformat == OWS_SFE_SCHEMA) /* reference GML 3.1.0 schema */
-    msIO_printf("\n  <xsd:import namespace=\"http://www.opengis.net/gml\"\n"
+    msIO_printf("\n  <import namespace=\"http://www.opengis.net/gml\"\n"
        "          schemaLocation=\"%s/gml/3.1.0/base/feature.xsd\" />\n", encoded);
   else /* default GML 2.1.x schema */
-    msIO_printf("\n  <xsd:import namespace=\"http://www.opengis.net/gml\"\n"
+    msIO_printf("\n  <import namespace=\"http://www.opengis.net/gml\"\n"
          "          schemaLocation=\"%s/gml/2.1.2/feature.xsd\" />\n", encoded);
   msFree(encoded);

@@ -756,14 +757,14 @@
     value = msOWSLookupMetadata(&(map->web.metadata), "FO", "feature_collection");
     if(value) collection_name = value;

-    msIO_printf("  <xsd:element name=\"%s\" type=\"%sType\"
substitutionGroup=\"gml:FeatureCollection\"/>\n", collection_name, collection_name);
-    msIO_printf("  <xsd:complexType name=\"%sType\">\n", collection_name);
-    msIO_printf("    <xsd:complexContent>\n");
-    msIO_printf("      <xsd:extension
base=\"gml:AbstractFeatureCollectionType\">\n");
-    msIO_printf("        <xsd:attribute name=\"version\" type=\"string\"
use=\"required\" fixed=\"1.0.0\"/>\n");
-    msIO_printf("      </xsd:extension>\n");
-    msIO_printf("    </xsd:complexContent>\n");
-    msIO_printf("  </xsd:complexType>\n");
+    msIO_printf("  <element name=\"%s\" type=\"%s:%sType\"
substitutionGroup=\"gml:FeatureCollection\"/>\n", collection_name,
user_namespace_prefix, collection_name);
+    msIO_printf("  <complexType name=\"%sType\">\n", collection_name);
+    msIO_printf("    <complexContent>\n");
+    msIO_printf("      <extension base=\"gml:AbstractFeatureCollectionType\">\n");
+    msIO_printf("        <attribute name=\"version\" type=\"string\"
use=\"required\" fixed=\"1.0.0\"/>\n");
+    msIO_printf("      </extension>\n");
+    msIO_printf("    </complexContent>\n");
+    msIO_printf("  </complexType>\n");
   } 

   /*
@@ -787,16 +788,23 @@
       */
       /* value = msOWSLookupMetadata(&(lp->metadata), "OFG", "layername"); */      
       encoded_name = msEncodeHTMLEntities( lp->name );
+      if (user_namespace_prefix)
    msIO_printf("\n"
-           "  <xsd:element name=\"%s\" \n"
-           "           type=\"%sType\" \n"
+           "  <element name=\"%s\" \n"
+           "           type=\"%s:%sType\" \n"
+           "           substitutionGroup=\"gml:_Feature\" />\n\n",
+           encoded_name, user_namespace_prefix, encoded_name);
+      else
+   msIO_printf("\n"
+           "  <element name=\"%s\" \n"
+           "           type=\"ms:%sType\" \n"
            "           substitutionGroup=\"gml:_Feature\" />\n\n",
            encoded_name, encoded_name);

-      msIO_printf("  <xsd:complexType name=\"%sType\">\n", encoded_name);
-      msIO_printf("    <xsd:complexContent>\n");
-      msIO_printf("      <xsd:extension base=\"gml:AbstractFeatureType\">\n");
-      msIO_printf("        <xsd:sequence>\n");
+      msIO_printf("  <complexType name=\"%sType\">\n", encoded_name);
+      msIO_printf("    <complexContent>\n");
+      msIO_printf("      <extension base=\"gml:AbstractFeatureType\">\n");
+      msIO_printf("        <sequence>\n");

       if (msLayerOpen(lp) == MS_SUCCESS) {
    if (msLayerGetItems(lp) == MS_SUCCESS) {      
@@ -844,17 +852,17 @@
    msIO_printf("\n\n<!-- ERROR: Failed openinig layer %s -->\n\n", encoded_name);
       }

-      msIO_printf("        </xsd:sequence>\n");
-      msIO_printf("      </xsd:extension>\n");
-      msIO_printf("    </xsd:complexContent>\n");
-      msIO_printf("  </xsd:complexType>\n");      
+      msIO_printf("        </sequence>\n");
+      msIO_printf("      </extension>\n");
+      msIO_printf("    </complexContent>\n");
+      msIO_printf("  </complexType>\n");      
     }
   }

   /*
   ** Done!
   */
-  msIO_printf("\n</xsd:schema>\n");
+  msIO_printf("\n</schema>\n");

   msFree(encoded_name);
   msFree(user_namespace_uri_encoded);
@@ -1243,23 +1251,6 @@
     encoded_typename = msEncodeHTMLEntities( typename );
     encoded_schema = msEncodeHTMLEntities( msOWSGetSchemasLocation(map) );
     if(outputformat == OWS_GML2) /* use a wfs:FeatureCollection */
-    {
-      if (strlen(user_namespace_prefix) == 0)
-      {
-      msIO_printf("<wfs:FeatureCollection\n"
-                  "   xmlns=\"%s\"\n"
-                  "   xmlns:wfs=\"http://www.opengis.net/wfs\"\n"
-                  "   xmlns:gml=\"http://www.opengis.net/gml\"\n"
-                  "   xmlns:ogc=\"http://www.opengis.net/ogc\"\n"
-                  "   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
-                  "   xsi:schemaLocation=\"http://www.opengis.net/wfs
%s/wfs/%s/WFS-basic.xsd \n"
-                  "                       %s
%sSERVICE=WFS&amp;VERSION=%s&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=%s&amp;OUTPUTFORMAT=%s\">\n",
-                  user_namespace_uri_encoded,
-                  encoded_schema, encoded, user_namespace_uri_encoded,
-                  script_url_encoded, encoded, encoded_typename,
output_schema_format);
-      }
-      else
-      {
       msIO_printf("<wfs:FeatureCollection\n"
          "   xmlns:%s=\"%s\"\n"  
          "   xmlns:wfs=\"http://www.opengis.net/wfs\"\n"
@@ -1271,8 +1262,6 @@
          user_namespace_prefix, user_namespace_uri_encoded,
          encoded_schema, encoded, user_namespace_uri_encoded, 
          script_url_encoded, encoded, encoded_typename, output_schema_format);
-      }
-    }
     else 
       msIO_printf("<%s:%s\n"
          "   xmlns:%s=\"%s\"\n"  
@@ -1305,14 +1294,7 @@
     if(outputformat == OWS_GML2)
       msIO_printf("</wfs:FeatureCollection>\n\n");
     else
-      if (strlen(user_namespace_prefix) == 0)
-      {
-        msIO_printf("</%s>\n\n", collection_name);
-      }
-      else
-      {
-   msIO_printf("</%s:%s>\n\n", user_namespace_prefix, collection_name);
-      }
+      msIO_printf("</%s:%s>\n\n", user_namespace_prefix, collection_name);

     /*
     ** Done! Now a bit of clean-up.
tbonfort commented 12 years ago

Author: bartvde@osgis.nl Date: 2006/11/02 - 13:26

Putting this one to INVALID since this has been fixed in the OGR GML driver instead.