Skip to content

Commit 6aedf02

Browse files
committed
[BUGFIX][Server] DescribeFeature does not clean attribute name
In GML, the attributes have to be cleaned to be used as an XML name.
1 parent 7f4f4e5 commit 6aedf02

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/server/qgswfsprojectparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle
464464

465465
//xsd:element
466466
QDomElement attElem = doc.createElement( "element"/*xsd:element*/ );
467-
attElem.setAttribute( "name", attributeName );
467+
attElem.setAttribute( "name", attributeName.replace( " ", "_" ) );
468468
QVariant::Type attributeType = fields[idx].type();
469469
if ( attributeType == QVariant::Int )
470470
attElem.setAttribute( "type", "integer" );

src/server/qgswfsserver.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
523523
QStringList::const_iterator alstIt;
524524
QList<int> idxList;
525525
QgsFields fields = layer->pendingFields();
526+
// build corresponding propertyname
527+
QList<QString> propertynames;
528+
for ( int idx = 0; idx < fields.count(); ++idx )
529+
{
530+
propertynames.append( fields[idx].name().replace( " ", "_" ) );
531+
}
526532
QString fieldName;
527533
QDomElement propertyElem;
528534
for ( int q = 0; q < queryChildNodes.size(); q++ )
@@ -535,7 +541,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
535541
{
536542
fieldName = fieldName.section( ":", 1, 1 );
537543
}
538-
int fieldNameIdx = fields.fieldNameIndex( fieldName );
544+
int fieldNameIdx = propertynames.indexOf( fieldName );
539545
if ( fieldNameIdx > -1 )
540546
{
541547
idxList.append( fieldNameIdx );
@@ -2072,7 +2078,7 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
20722078
continue;
20732079
}
20742080

2075-
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( QString( " " ), QString( "_" ) ) );
2081+
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ) );
20762082
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
20772083
fieldElem.appendChild( fieldText );
20782084
typeNameElement.appendChild( fieldElem );
@@ -2156,7 +2162,7 @@ QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc
21562162
continue;
21572163
}
21582164

2159-
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( QString( " " ), QString( "_" ) ) );
2165+
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ) );
21602166
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
21612167
fieldElem.appendChild( fieldText );
21622168
typeNameElement.appendChild( fieldElem );

0 commit comments

Comments
 (0)