From 9bd1835781d8dfa772feec19aec27613ebfc8a97 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Mon, 9 Aug 2010 16:11:44 +0000 Subject: add support for "nil" in XML-RPC --- example/tests/tests.cpp | 6 ++++++ example/tests/tests.h | 1 + source/xmlrpc.cpp | 10 ++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/example/tests/tests.cpp b/example/tests/tests.cpp index 86c6d4c9..de48ef62 100644 --- a/example/tests/tests.cpp +++ b/example/tests/tests.cpp @@ -377,6 +377,12 @@ void TestXmlRpc::testInt() QByteArray("-12")); } +void TestXmlRpc::testNil() +{ + checkVariant(QVariant(), + QByteArray("")); +} + void TestXmlRpc::testString() { checkVariant(QString("hello world"), diff --git a/example/tests/tests.h b/example/tests/tests.h index d7367628..7e50cf1c 100644 --- a/example/tests/tests.h +++ b/example/tests/tests.h @@ -69,6 +69,7 @@ private slots: void testDateTime(); void testDouble(); void testInt(); + void testNil(); void testString(); void testArray(); diff --git a/source/xmlrpc.cpp b/source/xmlrpc.cpp index e64a0620..59e61a79 100644 --- a/source/xmlrpc.cpp +++ b/source/xmlrpc.cpp @@ -66,9 +66,11 @@ void XMLRPC::marshall( QXmlStreamWriter *writer, const QVariant &value) } default: { - if( value.canConvert(QVariant::String) ) + if (value.isNull()) + writer->writeEmptyElement("nil"); + else if( value.canConvert(QVariant::String) ) { - writer->writeTextElement( "string", value.toString() ); + writer->writeTextElement("string", value.toString() ); } break; } @@ -92,6 +94,10 @@ QVariant XMLRPC::demarshall(const QDomElement &elem, QStringList &errors) const QDomElement typeData = elem.firstChild().toElement(); const QString typeName = typeData.tagName().toLower(); + if (typeName == "nil") + { + return QVariant(); + } if ( typeName == "string" ) { return QVariant( typeData.text() ); -- cgit v1.2.3