/*
Esta funcion busca en el xmlDocumento hasta que encuentra el tag y retorna el valor del string contenido por el
@param tag: Es la etiqueta que contiene el texto buscado.
*/
QString SbXmlInterprete::xmlObtenerTexto(QString tag)
{
 	xmlElemento = xmlDocumento.documentElement(); // retorna la raiz del documento
	QDomNode nodo = xmlElemento.firstChild(); // se obtiene el primer Hijo

//	std::cout << "tagName: " << xmlElemento.tagName() << std::endl;
	
	while( ! nodo.isNull())
	{
		QDomElement elemento = nodo.toElement();
		QDomNode hijo = elemento.firstChild();

		while (! hijo.isNull())
		{
			QDomElement elemento2 = hijo.toElement();
			if ( !elemento2.isNull() )
			{
				QString tmpTagName = elemento2.tagName();
//				std::cout << tmpTagName;
				QDomText textChild = hijo.firstChild().toText();
				
				QString tmpTextData = textChild.nodeValue();
//				std::cout << ": " << tmpTextData << std::endl;
				if (elemento2.tagName() == tag)
				{
					return tmpTextData;
				}
			}
			hijo = hijo.nextSibling();
		}
		nodo = nodo.nextSibling();
	}
	return "";
}
Beispiel #2
0
void UPnpDeviceDesc::SetNumValue( const QDomNode &n, int &nValue )
{
    if (!n.isNull())
    {
        QDomText  oText = n.firstChild().toText();

        if (!oText.isNull())
            nValue = oText.nodeValue().toInt();
    }
}
Beispiel #3
0
void UPnpDeviceDesc::SetStrValue( const QDomNode &n, QString &sValue )
{
    if (!n.isNull())
    {
        QDomText  oText = n.firstChild().toText();

        if (!oText.isNull())
            sValue = oText.nodeValue();
    }
}
Beispiel #4
0
int BeerXMLElement::getInt(const QDomText& textNode)
{
   bool ok;
   int ret;
   QString text = textNode.nodeValue();

   ret = text.toInt(&ok);
   if( !ok )
      Brewtarget::logE(QString("BeerXMLElement::getInt: %1 is not an integer. Line %2").arg(text).arg(textNode.lineNumber()) );

   return ret;
}
Beispiel #5
0
bool BeerXMLElement::getBool(const QDomText& textNode)
{
   QString text = textNode.nodeValue();

   if( text == "TRUE" )
      return true;
   else if( text == "FALSE" )
      return false;
   else
      Brewtarget::logE(QString("BeerXMLElement::getBool: %1 is not a boolean value. Line %2").arg(text).arg(textNode.lineNumber()) );

   return false;
}
Beispiel #6
0
QDateTime BeerXMLElement::getDateTime( QDomText const& textNode )
{
   bool ok = true;
   QDateTime ret;
   QString text = textNode.nodeValue();

   ret = QDateTime::fromString(text, Qt::ISODate);
   ok = ret.isValid();
   if( !ok )
      Brewtarget::logE(QString("BeerXMLElement::getDateTime: %1 is not a date. Line %2").arg(text).arg(textNode.lineNumber()) );

   return ret;
}
Beispiel #7
0
void UPnpDeviceDesc::SetBoolValue( const QDomNode &n, bool &nValue )
{
    if (!n.isNull())
    {
        QDomText  oText = n.firstChild().toText();

        if (!oText.isNull())
        {
            QString s = oText.nodeValue();
            nValue = (s == "yes" || s == "true" || s.toInt());
        }
    }
}
Beispiel #8
0
// getVal =====================================================================
double BeerXMLElement::getDouble(const QDomText& textNode)
{
   bool ok;
   double ret;

   QString text = textNode.nodeValue();

   // ret = text.toDouble(&ok);
   ret = Brewtarget::toDouble(text,&ok);
   if( !ok )
      Brewtarget::logE(QString("BeerXMLElement::getDouble: %1 is not a number. Line %2").arg(text).arg(textNode.lineNumber()) );

   return ret;
}
Beispiel #9
0
QString XmlConfiguration::GetValue( const QString &sSetting, QString sDefault ) 
{
    QDomNode node = FindNode( sSetting );

    if (!node.isNull())
    {
        // -=>TODO: This Always assumes firstChild is a Text Node... should change
        QDomText  oText = node.firstChild().toText();

        if (!oText.isNull())
            return oText.nodeValue();
    }

    return sDefault;
}
Beispiel #10
0
QDomText EmoticonExpander::insertEmoticon(QDomText textNode, const Emoticon &emoticon, int index) const
{
    int emoticonLength = emoticon.triggerText().length();

    QDomText afterEmoticon = textNode.splitText(index + emoticonLength);
    textNode.setNodeValue(textNode.nodeValue().mid(0, index));

    QDomElement emoticonElement = textNode.ownerDocument().createElement("img");
    emoticonElement.setAttribute("emoticon", emoticon.triggerText());
    emoticonElement.setAttribute("title", emoticon.triggerText());
    emoticonElement.setAttribute("alt", emoticon.triggerText());
    emoticonElement.setAttribute("src", "file:///" + m_pathProvider->emoticonPath(emoticon));
    textNode.parentNode().insertBefore(emoticonElement, afterEmoticon);

    return afterEmoticon;
}
void OutlineTree::getHeaderInformation( const QDomElement &header )
{
    // visit all children of the header element and look if you can make
    // something with it
    QDomNode node = header.firstChild();
    while ( !node.isNull() ) {
	if ( node.isElement() ) {
	    // case for the different header entries
	    if ( node.nodeName() == "title" ) {
		QDomText textChild = node.firstChild().toText();
		if ( !textChild.isNull() ) {
		    setColumnText( 0, textChild.nodeValue() );
		}
	    }
	}
	node = node.nextSibling();
    }
}
Beispiel #12
0
QDate BeerXMLElement::getDate( QDomText const& textNode )
{
   bool ok = true;
   QDate ret;
   QString text = textNode.nodeValue();

   ret = QDate::fromString(text, "M/d/yyyy");
   ok = ret.isValid();
   // Dates have some odd inconsistencies.
   if( !ok )
   {
      ret = QDate::fromString(text,"d/M/yyyy");
      ok = ret.isValid();
   }

   if ( !ok )
      Brewtarget::logE(QString("BeerXMLElement::getDate: %1 is not an ISO date-time. Line %2").arg(text).arg(textNode.lineNumber()) );

   return ret;
}
Beispiel #13
0
QString SOAPClient::GetNodeValue( QDomNode &node, const QString &sName, const QString &sDefault )
{
    if (node.isNull())
        return sDefault;

    QString  sValue  = "";
    QDomNode valNode = FindNode( sName, node );

    if (!valNode.isNull())
    {
        // -=>TODO: Assumes first child is Text Node.

        QDomText  oText = valNode.firstChild().toText();

        if (!oText.isNull())
            sValue = oText.nodeValue();

        return QUrl::fromPercentEncoding(sValue.toUtf8());
    }

    return sDefault;
}
/**
 * Parses an xml reply form a start
 * @param xmlMessage XML message with tags data as root
 * @return Path of the decode file, or "" if there have been an error while parsing
 */
QString NMGNetperfXMLInterpret::getResultFilePathFromResult ( const QString & xmlMessage )
{
	QDomDocument doc;
	if ( !doc.setContent ( xmlMessage ) )
	{
		cerr << "Error: the document is not well formed." << endl;
		return "";
	}
	QDomElement root = doc.documentElement();
	QString resultPath = "";

	if ( root.tagName() != TAG_DATA )
		cerr << "Error root element at NMGNetperfXMLInterpret different from data (" << qPrintable ( root.tagName() ) << ")." << endl;
	else
	{
		for ( QDomNode node = root.firstChild(); !node.isNull(); node = node.nextSibling() )
		{
			if ( node.isElement() )
			{
				QDomElement elem = node.toElement();
				if ( elem.tagName() == TAG_DECODE_FILE )
				{
					QDomText id = elem.firstChild().toText();
					if ( id.isNull() )
						cerr << "Result file path node has no value!" << endl;
				}
				else if ( elem.tagName() == TAG_TEST_FILE )
				{
					QDomText id = elem.firstChild().toText();
					if ( !id.isNull() ) resultPath = id.nodeValue();
					else cerr << "Result file path node has no value!" << endl;
				}
				else cerr << "Incorrect Tag in Netperf XML reply (" << qPrintable ( elem.tagName() ) << ")." << endl;
			}
		}
	}
	return resultPath;
}
/**
 * Parses the status message and returns the integer value of the status
 * @param xmlMessage
 * @return Status value or -1 if error
 */
int NMGNetperfXMLInterpret::parseStatusMessage ( const QString & xmlMessage )
{
	QDomDocument doc;
	if ( !doc.setContent ( xmlMessage ) )
	{
		cerr << "Error: the document is not well formed." << endl;
		return -1;
	}
	QDomElement root = doc.documentElement();

	if ( root.tagName() != TAG_DATA )
		cerr << "Error root element at NMGNetperfXMLInterpret different from data (" << qPrintable ( root.tagName() ) << ")." << endl;
	else
	{
		for ( QDomNode node = root.firstChild(); !node.isNull(); node = node.nextSibling() )
		{
			if ( node.isElement() )
			{
				QDomElement elem = node.toElement();
				if ( elem.tagName() == TAG_STATUS )
				{
					QDomText id = elem.firstChild().toText();
					if ( !id.isNull() )
					{
						bool ok;
						int num = id.nodeValue().toInt ( &ok );
						if ( ok ) return num;
					}
					else cerr << "The status node has no value!" << endl;
				}
#ifdef DEBUG
				else cerr << "Tag not managed in Netperf Status XML (" << elem.tagName() << ")." << endl;
#endif
			}
		}
	}
	return -1;
}
Beispiel #16
0
QDomText EmoticonExpander::expandFirstEmoticon(QDomText textNode) const
{
    QString text = textNode.nodeValue().toLower();
    int textLength = text.length();

    if (0 == textLength)
        return QDomText();

    int currentEmoticonStart = -1;
    Emoticon currentEmoticon;

    EmoticonWalker walker(m_tree);

    for (int i = 0; i < textLength; i++)
    {
        Emoticon emoticon = walker.matchEmoticon(text.at(i), (i < textLength - 1) && text.at(i + 1).isLetter());
        if (emoticon.isNull())
            continue;

        // TODO: remove this dependency
        int emoticonStart = i - emoticon.triggerText().length() + 1;
        if (currentEmoticon.isNull() || currentEmoticonStart >= emoticonStart)
        {
            currentEmoticon = emoticon;
            currentEmoticonStart = emoticonStart;
            continue;
        }

        return insertEmoticon(textNode, currentEmoticon, currentEmoticonStart);
    }

    if (!currentEmoticon.isNull())
        insertEmoticon(textNode, currentEmoticon, currentEmoticonStart);

    return QDomText();
}
Beispiel #17
0
Feature* parsePoint(QDomElement& e, Layer* aLayer)
{
    Node* P = NULL;

    QDomElement c = e.firstChildElement();
    while(!c.isNull() && !P) {
        if (c.tagName() == "coordinates") {
            QDomText t = c.firstChild().toText();
            QString s = t.nodeValue();
            QStringList tokens = s.split(",");
            qreal lon = tokens[0].toDouble();
            qreal lat = tokens[1].toDouble();
            Coord p(lon,lat);

            P = g_backend.allocNode(aLayer, p);
            aLayer->add(P);
            P->setTag("%kml:guid", kmlId);
        }

        c = c.nextSiblingElement();
    }

    return P;
}
/**
 * Parses an xml reply form a start
 * @param xmlMessage XML message with tags data as root
 * @return Path of the decode file, or "" if there have been an error while parsing
 */
QString NMGMGenXMLInterpret::getResultFilePathFromResult(const QString & xmlMessage)
{
	QDomDocument doc;
	if(!doc.setContent(xmlMessage))
	{
		cerr << RED << "[ERROR] the document is not well formed." << ENDCOLOR << endl;
		return "";
	}
	NMGQDomSortElement root = doc.documentElement();
	QString resultPath = "";
	
	if(root.tagName()!=TAG_DATA) 
		cerr << RED << "[ERROR] root element at NMGMGenXMLInterpret different from data ("<< qPrintable(root.tagName()) <<")."<< ENDCOLOR <<endl;
	else
	{
		for(QDomNode node = root.firstChild(); !node.isNull(); node = node.nextSibling())
		{
			if(node.isElement())
			{
				NMGQDomSortElement elem = node.toElement();
				if(elem.tagName()==TAG_DECODE_FILE)
				{
					QString text = "";
					QDomText id = elem.firstChild().toText();
					if(!id.isNull()) text = id.nodeValue();
					//if(!id.isNull()) resultPath = id.nodeValue();
					//else cerr << "The decode result path node has no value!" << endl;
				}
				else if(elem.tagName()==TAG_RESULT_FILE)
				{
					QString text = "";
					QDomText id = elem.firstChild().toText();
					if(!id.isNull()) text = id.nodeValue();
					
				}
				else if(elem.tagName()==TAG_TEST_FILE)
				{
					//QString text = "";
					QDomText id = elem.firstChild().toText();
					if(!id.isNull()) resultPath = id.nodeValue();
					else cerr << "The decode result path node has no value!" << endl;
				}
				else if(elem.tagName()==TAG_RESULT_GRAPH_OWDD)
				{
					QString text = "";
					QDomText id = elem.firstChild().toText();
					if(!id.isNull()) text = id.nodeValue();
					
				}
				else if(elem.tagName()==TAG_RESULT_GRAPH_IPDV)
				{
					QString text = "";
					QDomText id = elem.firstChild().toText();
					if(!id.isNull()) text = id.nodeValue();
					
				}
				else if(elem.tagName()==TAG_RESULT_GRAPH_IPDVD)
				{
					QString text = "";
					QDomText id = elem.firstChild().toText();
					if(!id.isNull()) text = id.nodeValue();
					
				}
				else if(elem.tagName()==TAG_TIME_FILE)
				{
					
				}
				else cerr << "Tag not correct in Mgen XML reply (" << qPrintable(elem.tagName()) <<")." << endl;
			}
		}
	}
	return resultPath;
}
Beispiel #19
0
bool SOAPClient::SendSOAPRequest( const QString    &sMethod, 
                                        QStringMap &list, 
                                        int        &nErrCode, 
                                        QString    &sErrDesc,
                                        bool        bInQtThread )
{
    QUrl url( m_url );

    url.setPath( m_sControlPath );

    // --------------------------------------------------------------
    // Add appropriate headers
    // --------------------------------------------------------------

    QHttpRequestHeader header;

    header.setValue("CONTENT-TYPE", "text/xml; charset=\"utf-8\"" );
    header.setValue("SOAPACTION"  , QString( "\"%1#GetConnectionInfo\"" )
                                       .arg( m_sNamespace ));

    // --------------------------------------------------------------
    // Build request payload
    // --------------------------------------------------------------

    QByteArray  aBuffer;
    QTextStream os( &aBuffer );

    os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"; 
    os << "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
    os << " <s:Body>\r\n";
    os << "  <u:" << sMethod << " xmlns:u=\"" << m_sNamespace << "\">\r\n";

    // --------------------------------------------------------------
    // Add parameters from list
    // --------------------------------------------------------------

    for ( QStringMap::iterator it  = list.begin(); 
                               it != list.end(); 
                             ++it ) 
    {                                                               
        os << "   <" << it.key() << ">";
        os << HTTPRequest::Encode( *it );
        os << "</"   << it.key() << ">\r\n";
    }

    os << "  </u:" << sMethod << ">\r\n";
    os << " </s:Body>\r\n";
    os << "</s:Envelope>\r\n";

    os.flush();

    // --------------------------------------------------------------
    // Perform Request
    // --------------------------------------------------------------

    QBuffer     buff( &aBuffer );

    QString sXml = HttpComms::postHttp( url, 
                                        &header,
                                        (QIODevice *)&buff,
                                        10000, // ms
                                        3,     // retries
                                        0,     // redirects
                                        false, // allow gzip
                                        NULL,  // login
                                        bInQtThread );

    // --------------------------------------------------------------
    // Parse response
    // --------------------------------------------------------------

    list.clear();

    QDomDocument doc;

    if ( !doc.setContent( sXml, true, &sErrDesc, &nErrCode ))
    {
        VERBOSE( VB_UPNP, QString( "MythXMLClient::SendSOAPRequest( %1 ) - Invalid response from %2" )
                             .arg( sMethod   )
                             .arg( url.toString() ));
        return false;
    }

    // --------------------------------------------------------------
    // Is this a valid response?
    // --------------------------------------------------------------

    QString      sResponseName = sMethod + "Response";
    QDomNodeList oNodeList     = doc.elementsByTagNameNS( m_sNamespace, sResponseName );

    if (oNodeList.count() > 0)
    {
        QDomNode oMethod = oNodeList.item(0);

        if (!oMethod.isNull())
        {

            for ( QDomNode oNode = oMethod.firstChild(); !oNode.isNull(); 
                           oNode = oNode.nextSibling() )
            {
                QDomElement e = oNode.toElement();

                if (!e.isNull())
                {
                    QString sName  = e.tagName();
                    QString sValue = "";
    
                    QDomText  oText = oNode.firstChild().toText();
    
                    if (!oText.isNull())
                        sValue = oText.nodeValue();

                    list.insert(QUrl::fromPercentEncoding(sName.toUtf8()),
                                QUrl::fromPercentEncoding(sValue.toUtf8()));
                }
            }
        }

        return true;
    }

    // --------------------------------------------------------------
    // Must be a fault... parse it to return reason
    // --------------------------------------------------------------

    nErrCode = GetNodeValue( doc, "Envelope/Body/Fault/detail/UPnPResult/errorCode"       , 500 );
    sErrDesc = GetNodeValue( doc, "Envelope/Body/Fault/detail/UPnPResult/errorDescription", QString( "Unknown" ));

    return false;
}
Beispiel #20
0
/** Actually sends the sMethod action to the command URL specified
 *  in the constructor (url+[/]+sControlPath).
 *
 * \param sMethod method to be invoked. e.g. "SetChannel",
 *                "GetConnectionInfoResult"
 *
 * \param list Parsed as a series of key value pairs for the input params
 *             and then cleared and used for the output params.
 *
 * \param nErrCode set to zero on success, non-zero in case of error.
 *
 * \param sErrCode returns error description from device, when applicable.
 *
 * \param bInQtThread May be set to true if this is run from within
 *                    a QThread with a running an event loop.
 *
 * \return Returns a QDomDocument containing output parameters on success.
 */
QDomDocument SOAPClient::SendSOAPRequest(const QString &sMethod,
                                         QStringMap    &list,
                                         int           &nErrCode,
                                         QString       &sErrDesc,
                                         bool           bInQtThread)
{
    QUrl url(m_url);

    url.setPath(m_sControlPath);

    nErrCode = UPnPResult_Success;
    sErrDesc = "";

    QDomDocument xmlResult;
    if (m_sNamespace.isEmpty())
    {
        nErrCode = UPnPResult_MythTV_NoNamespaceGiven;
        sErrDesc = "No namespace given";
        return xmlResult;
    }

    // --------------------------------------------------------------
    // Add appropriate headers
    // --------------------------------------------------------------

    QHttpRequestHeader header("POST", sMethod, 1, 0);

    header.setValue("CONTENT-TYPE", "text/xml; charset=\"utf-8\"" );
    header.setValue("SOAPACTION",
                    QString("\"%1#%2\"").arg(m_sNamespace).arg(sMethod));

    // --------------------------------------------------------------
    // Build request payload
    // --------------------------------------------------------------

    QByteArray  aBuffer;
    QTextStream os( &aBuffer );

    os.setCodec("UTF-8");

    os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"; 
    os << "<s:Envelope "
        " s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\""
        " xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
    os << " <s:Body>\r\n";
    os << "  <u:" << sMethod << " xmlns:u=\"" << m_sNamespace << "\">\r\n";

    // --------------------------------------------------------------
    // Add parameters from list
    // --------------------------------------------------------------

    for (QStringMap::iterator it = list.begin(); it != list.end(); ++it)
    {                                                               
        os << "   <" << it.key() << ">";
        os << HTTPRequest::Encode( *it );
        os << "</"   << it.key() << ">\r\n";
    }

    os << "  </u:" << sMethod << ">\r\n";
    os << " </s:Body>\r\n";
    os << "</s:Envelope>\r\n";

    os.flush();

    // --------------------------------------------------------------
    // Perform Request
    // --------------------------------------------------------------

    QBuffer buff(&aBuffer);

    LOG(VB_UPNP, LOG_DEBUG,
        QString("SOAPClient(%1) sending:\n").arg(url.toString()) +
        header.toString() + QString("\n%1\n").arg(aBuffer.constData()));

    QString sXml =
        HttpComms::postHttp(url,
                            &header,
                            &buff, // QIODevice*
                            10000, // ms -- Technically should be 30ms per spec
                            3,     // retries
                            0,     // redirects
                            false, // allow gzip
                            NULL,  // login
                            bInQtThread,
                            QString() // userAgent, UPnP/1.0 very strict on
                                      // format if set
        );

    // --------------------------------------------------------------
    // Parse response
    // --------------------------------------------------------------

    LOG(VB_UPNP, LOG_DEBUG, "SOAPClient response:\n" +
                            QString("%1\n").arg(sXml));

    // TODO handle timeout without response correctly.

    list.clear();

    QDomDocument doc;

    if (!doc.setContent(sXml, true, &sErrDesc, &nErrCode))
    {
        LOG(VB_UPNP, LOG_ERR,
            QString("SendSOAPRequest( %1 ) - Invalid response from %2")
                .arg(sMethod).arg(url.toString()) + 
            QString("%1: %2").arg(nErrCode).arg(sErrDesc));

        return xmlResult;
    }

    // --------------------------------------------------------------
    // Is this a valid response?
    // --------------------------------------------------------------

    QString      sResponseName = sMethod + "Response";
    QDomNodeList oNodeList     =
        doc.elementsByTagNameNS(m_sNamespace, sResponseName);

    if (oNodeList.count() == 0)
    {
        // --------------------------------------------------------------
        // Must be a fault... parse it to return reason
        // --------------------------------------------------------------

        nErrCode = GetNodeValue(
            doc, "Envelope/Body/Fault/detail/UPnPError/errorCode", 500);
        sErrDesc = GetNodeValue(
            doc, "Envelope/Body/Fault/detail/UPnPError/errorDescription", "");
        if (sErrDesc.isEmpty())
            sErrDesc = QString("Unknown #%1").arg(nErrCode);

        QDomNode oNode  = FindNode( "Envelope/Body/Fault", doc );

        oNode = xmlResult.importNode( oNode, true );
        xmlResult.appendChild( oNode );

        return xmlResult;
    }

    QDomNode oMethod = oNodeList.item(0);
    if (oMethod.isNull())
        return xmlResult;

    QDomNode oNode = oMethod.firstChild(); 
    for (; !oNode.isNull(); oNode = oNode.nextSibling())
    {
        QDomElement e = oNode.toElement();
        if (e.isNull())
            continue;

        QString sName  = e.tagName();
        QString sValue = "";
    
        QDomText  oText = oNode.firstChild().toText();
    
        if (!oText.isNull())
            sValue = oText.nodeValue();

        list.insert(QUrl::fromPercentEncoding(sName.toUtf8()),
                    QUrl::fromPercentEncoding(sValue.toUtf8()));
    }

    // Create copy of oMethod that can be used with xmlResult.

    oMethod = xmlResult.importNode( oMethod.firstChild(), true  );

    // importNode does not attach the new nodes to the document,
    // do it here.

    xmlResult.appendChild( oMethod );

    return xmlResult;
}
Beispiel #21
0
QString BeerXMLElement::getString( QDomText const& textNode )
{
   return textNode.nodeValue();
}
Beispiel #22
0
QDomDocument SOAPClient::SendSOAPRequest(const QString &sMethod,
                                         QStringMap    &list,
                                         int           &nErrCode,
                                         QString       &sErrDesc)
{
    QUrl url(m_url);

    url.setPath(m_sControlPath);

    nErrCode = UPnPResult_Success;
    sErrDesc = "";

    QDomDocument xmlResult;
    if (m_sNamespace.isEmpty())
    {
        nErrCode = UPnPResult_MythTV_NoNamespaceGiven;
        sErrDesc = "No namespace given";
        return xmlResult;
    }

    // --------------------------------------------------------------
    // Add appropriate headers
    // --------------------------------------------------------------
    QHash<QByteArray, QByteArray> headers;

    headers.insert("Content-Type", "text/xml; charset=\"utf-8\"");
    QString soapHeader = QString("\"%1#%2\"").arg(m_sNamespace).arg(sMethod);
	headers.insert("SOAPACTION", soapHeader.toUtf8());
    headers.insert("User-Agent", "Mozilla/9.876 (X11; U; Linux 2.2.12-20 i686, en) "
                                 "Gecko/25250101 Netscape/5.432b1");
    // --------------------------------------------------------------
    // Build request payload
    // --------------------------------------------------------------

    QByteArray  aBuffer;
    QTextStream os( &aBuffer );

    os.setCodec("UTF-8");

    os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"; 
    os << "<s:Envelope "
        " s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\""
        " xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
    os << " <s:Body>\r\n";
    os << "  <u:" << sMethod << " xmlns:u=\"" << m_sNamespace << "\">\r\n";

    // --------------------------------------------------------------
    // Add parameters from list
    // --------------------------------------------------------------

    for (QStringMap::iterator it = list.begin(); it != list.end(); ++it)
    {                                                               
        os << "   <" << it.key() << ">";
        os << HTTPRequest::Encode( *it );
        os << "</"   << it.key() << ">\r\n";
    }

    os << "  </u:" << sMethod << ">\r\n";
    os << " </s:Body>\r\n";
    os << "</s:Envelope>\r\n";

    os.flush();

    // --------------------------------------------------------------
    // Perform Request
    // --------------------------------------------------------------

    LOG(VB_UPNP, LOG_DEBUG,
        QString("SOAPClient(%1) sending:\n %2").arg(url.toString()).arg(aBuffer.constData()));

    QString sXml;

    if (!GetMythDownloadManager()->postAuth(url.toString(), &aBuffer, NULL, NULL, &headers))
    {
        LOG(VB_GENERAL, LOG_ERR, QString("SOAPClient::SendSOAPRequest: request failed: %1")
                                         .arg(url.toString()));
    }
    else
        sXml = QString(aBuffer);

    // --------------------------------------------------------------
    // Parse response
    // --------------------------------------------------------------

    LOG(VB_UPNP, LOG_DEBUG, "SOAPClient response:\n" +
                            QString("%1\n").arg(sXml));

    // TODO handle timeout without response correctly.

    list.clear();

    QDomDocument doc;

    if (!doc.setContent(sXml, true, &sErrDesc, &nErrCode))
    {
        LOG(VB_UPNP, LOG_ERR,
            QString("SendSOAPRequest( %1 ) - Invalid response from %2")
                .arg(sMethod).arg(url.toString()) + 
            QString("%1: %2").arg(nErrCode).arg(sErrDesc));

        return xmlResult;
    }

    // --------------------------------------------------------------
    // Is this a valid response?
    // --------------------------------------------------------------

    QString      sResponseName = sMethod + "Response";
    QDomNodeList oNodeList     =
        doc.elementsByTagNameNS(m_sNamespace, sResponseName);

    if (oNodeList.count() == 0)
    {
        // --------------------------------------------------------------
        // Must be a fault... parse it to return reason
        // --------------------------------------------------------------

        nErrCode = GetNodeValue(
            doc, "Envelope/Body/Fault/detail/UPnPError/errorCode", 500);
        sErrDesc = GetNodeValue(
            doc, "Envelope/Body/Fault/detail/UPnPError/errorDescription", "");
        if (sErrDesc.isEmpty())
            sErrDesc = QString("Unknown #%1").arg(nErrCode);

        QDomNode oNode  = FindNode( "Envelope/Body/Fault", doc );

        oNode = xmlResult.importNode( oNode, true );
        xmlResult.appendChild( oNode );

        return xmlResult;
    }

    QDomNode oMethod = oNodeList.item(0);
    if (oMethod.isNull())
        return xmlResult;

    QDomNode oNode = oMethod.firstChild(); 
    for (; !oNode.isNull(); oNode = oNode.nextSibling())
    {
        QDomElement e = oNode.toElement();
        if (e.isNull())
            continue;

        QString sName  = e.tagName();
        QString sValue = "";
    
        QDomText  oText = oNode.firstChild().toText();
    
        if (!oText.isNull())
            sValue = oText.nodeValue();

        list.insert(QUrl::fromPercentEncoding(sName.toUtf8()),
                    QUrl::fromPercentEncoding(sValue.toUtf8()));
    }

    // Create copy of oMethod that can be used with xmlResult.

    oMethod = xmlResult.importNode( oMethod.firstChild(), true  );

    // importNode does not attach the new nodes to the document,
    // do it here.

    xmlResult.appendChild( oMethod );

    return xmlResult;
}