QDomNode QDomDocumentProto::removeChild(const QDomNode& oldChild) { QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject()); if (item) return item->removeChild(oldChild); return QDomNode(); }
void QgsWFSServer::sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QMap< int, QgsField > fields, QSet<QString> hiddenAttributes ) /*const*/ { QByteArray result; if ( format == "GeoJSON" ) { QString fcString; if ( featIdx == 0 ) fcString += " "; else fcString += " ,"; fcString += createFeatureGeoJSON( feat, crs, fields, hiddenAttributes ); fcString += "\n"; result = fcString.toUtf8(); request.sendGetFeatureResponse( &result ); fcString = ""; } else { QDomDocument gmlDoc; QDomElement featureElement = createFeatureElem( feat, gmlDoc, crs, fields, hiddenAttributes ); gmlDoc.appendChild( featureElement ); result = gmlDoc.toByteArray(); request.sendGetFeatureResponse( &result ); gmlDoc.removeChild( featureElement ); } }
void TestQgsOgcUtils::testGeometryToGML() { QDomDocument doc; QgsGeometry* geomPoint = QgsGeometry::fromPoint( QgsPoint( 111, 222 ) ); QgsGeometry* geomLine = QgsGeometry::fromWkt( "LINESTRING(111 222, 222 222)" ); // Test GML2 QDomElement elemInvalid = QgsOgcUtils::geometryToGML( 0, doc ); QVERIFY( elemInvalid.isNull() ); QDomElement elemPoint = QgsOgcUtils::geometryToGML( geomPoint, doc ); QVERIFY( !elemPoint.isNull() ); doc.appendChild( elemPoint ); QCOMPARE( doc.toString( -1 ), QString( "<gml:Point><gml:coordinates cs=\",\" ts=\" \">111,222</gml:coordinates></gml:Point>" ) ); doc.removeChild( elemPoint ); QDomElement elemLine = QgsOgcUtils::geometryToGML( geomLine, doc ); QVERIFY( !elemLine.isNull() ); doc.appendChild( elemLine ); QCOMPARE( doc.toString( -1 ), QString( "<gml:LineString><gml:coordinates cs=\",\" ts=\" \">111,222 222,222</gml:coordinates></gml:LineString>" ) ); doc.removeChild( elemLine ); // Test GML3 elemInvalid = QgsOgcUtils::geometryToGML( 0, doc, "GML3" ); QVERIFY( elemInvalid.isNull() ); elemPoint = QgsOgcUtils::geometryToGML( geomPoint, doc, "GML3" ); QVERIFY( !elemPoint.isNull() ); doc.appendChild( elemPoint ); QCOMPARE( doc.toString( -1 ), QString( "<gml:Point><gml:pos srsDimension=\"2\">111 222</gml:pos></gml:Point>" ) ); doc.removeChild( elemPoint ); elemLine = QgsOgcUtils::geometryToGML( geomLine, doc, "GML3" ); QVERIFY( !elemLine.isNull() ); doc.appendChild( elemLine ); QCOMPARE( doc.toString( -1 ), QString( "<gml:LineString><gml:posList srsDimension=\"2\">111 222 222 222</gml:posList></gml:LineString>" ) ); doc.removeChild( elemLine ); delete geomPoint; delete geomLine; }
TestResult::Status TestBaseLine::verify(const QString &serializedInput) const { switch(m_type) { case SchemaIsValid: /* Fall through. */ case Text: { if(serializedInput == details()) return TestResult::Pass; else return TestResult::Fail; } case Fragment: /* Fall through. */ case XML: { /* Read the baseline and the serialized input into two QDomDocuments, and compare * them deeply. We wrap fragments in a root node such that it is well-formed XML. */ QDomDocument output; { /* The reason we put things into a QByteArray and then parse it through QXmlSimpleReader, is that * QDomDocument does whitespace stripping when calling setContent(QString). In other words, * this workarounds a bug. */ QXmlInputSource source; source.setData((m_type == XML ? serializedInput : QLatin1String("<r>") + serializedInput + QLatin1String("</r>")).toUtf8()); QString outputReadingError; QXmlSimpleReader reader; reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); const bool success = output.setContent(&source, &reader, &outputReadingError); if(!success) return TestResult::Fail; Q_ASSERT(success); } QDomDocument baseline; { QXmlInputSource source; source.setData((m_type == XML ? details() : QLatin1String("<r>") + details() + QLatin1String("</r>")).toUtf8()); QString baselineReadingError; QXmlSimpleReader reader; reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); const bool success = baseline.setContent(&source, &reader, &baselineReadingError); if(!success) return TestResult::Fail; /* This piece of code workaround a bug in QDom, which treats XML prologs as processing * instructions and make them available in the tree as so. */ if(m_type == XML) { /* $doc/r/node() */ const QDomNodeList children(baseline.childNodes()); const int len = children.length(); for(int i = 0; i < len; ++i) { const QDomNode &child = children.at(i); if(child.isProcessingInstruction() && child.nodeName() == QLatin1String("xml")) { baseline.removeChild(child); break; } } } Q_ASSERT_X(baselineReadingError.isNull(), Q_FUNC_INFO, qPrintable((QLatin1String("Reading the baseline failed: ") + baselineReadingError))); } if(isDeepEqual(output, baseline)) return TestResult::Pass; else { pDebug() << "FAILURE:" << output.toString() << "is NOT IDENTICAL to(baseline):" << baseline.toString(); return TestResult::Fail; } } case Ignore: return TestResult::Pass; case Inspect: return TestResult::NotTested; case ExpectedError: { /* This function is only called for Text/XML/Fragment tests. */ return TestResult::Fail; } } Q_ASSERT(false); return TestResult::Fail; }