Skip to content

Commit

Permalink
[BUGFIX][Server] DescribeFeature does not clean attribute name
Browse files Browse the repository at this point in the history
In GML, the attributes have to be cleaned to be used as an XML name.
  • Loading branch information
rldhont committed Mar 16, 2018
1 parent 7f4f4e5 commit 6aedf02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/server/qgswfsprojectparser.cpp
Expand Up @@ -464,7 +464,7 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle

//xsd:element
QDomElement attElem = doc.createElement( "element"/*xsd:element*/ );
attElem.setAttribute( "name", attributeName );
attElem.setAttribute( "name", attributeName.replace( " ", "_" ) );
QVariant::Type attributeType = fields[idx].type();
if ( attributeType == QVariant::Int )
attElem.setAttribute( "type", "integer" );
Expand Down
12 changes: 9 additions & 3 deletions src/server/qgswfsserver.cpp
Expand Up @@ -523,6 +523,12 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QStringList::const_iterator alstIt;
QList<int> idxList;
QgsFields fields = layer->pendingFields();
// build corresponding propertyname
QList<QString> propertynames;
for ( int idx = 0; idx < fields.count(); ++idx )
{
propertynames.append( fields[idx].name().replace( " ", "_" ) );
}
QString fieldName;
QDomElement propertyElem;
for ( int q = 0; q < queryChildNodes.size(); q++ )
Expand All @@ -535,7 +541,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
{
fieldName = fieldName.section( ":", 1, 1 );
}
int fieldNameIdx = fields.fieldNameIndex( fieldName );
int fieldNameIdx = propertynames.indexOf( fieldName );
if ( fieldNameIdx > -1 )
{
idxList.append( fieldNameIdx );
Expand Down Expand Up @@ -2072,7 +2078,7 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
continue;
}

QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( QString( " " ), QString( "_" ) ) );
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ) );
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
fieldElem.appendChild( fieldText );
typeNameElement.appendChild( fieldElem );
Expand Down Expand Up @@ -2156,7 +2162,7 @@ QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc
continue;
}

QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( QString( " " ), QString( "_" ) ) );
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ) );
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
fieldElem.appendChild( fieldText );
typeNameElement.appendChild( fieldElem );
Expand Down

0 comments on commit 6aedf02

Please sign in to comment.