Skip to content

Commit 8b37bab

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 decb722 commit 8b37bab

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
@@ -522,6 +522,12 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
522522
QStringList::const_iterator alstIt;
523523
QList<int> idxList;
524524
QgsFields fields = layer->pendingFields();
525+
// build corresponding propertyname
526+
QList<QString> propertynames;
527+
for ( int idx = 0; idx < fields.count(); ++idx )
528+
{
529+
propertynames.append( fields[idx].name().replace( " ", "_" ) );
530+
}
525531
QString fieldName;
526532
QDomElement propertyElem;
527533
for ( int q = 0; q < queryChildNodes.size(); q++ )
@@ -534,7 +540,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
534540
{
535541
fieldName = fieldName.section( ":", 1, 1 );
536542
}
537-
int fieldNameIdx = fields.fieldNameIndex( fieldName );
543+
int fieldNameIdx = propertynames.indexOf( fieldName );
538544
if ( fieldNameIdx > -1 )
539545
{
540546
idxList.append( fieldNameIdx );
@@ -2047,7 +2053,7 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
20472053
continue;
20482054
}
20492055

2050-
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( QString( " " ), QString( "_" ) ) );
2056+
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ) );
20512057
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
20522058
fieldElem.appendChild( fieldText );
20532059
typeNameElement.appendChild( fieldElem );
@@ -2129,7 +2135,7 @@ QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc
21292135
continue;
21302136
}
21312137

2132-
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( QString( " " ), QString( "_" ) ) );
2138+
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ) );
21332139
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
21342140
fieldElem.appendChild( fieldText );
21352141
typeNameElement.appendChild( fieldElem );

0 commit comments

Comments
 (0)