XML special charecters reading problem



  • I use two functions to send xml file thru network. First one is:
    @bool ConfigurationDialog::sendNode(const QDomNode & node) {

    if (node.isNull())
    return false;

    UdpConnector * connector = GET_CONNECTOR_UDP();

    if (connector == NULL)
    return false;

    sxProperties cmd, result;
    cmd.insert(sxPropName::command,sxCommand::structure);
    cmd.insert(sxPropName::client, DeviceType::configurator);
    cmd.insert(sxPropName::action, ActionValue::set);
    cmd.insert(sxPropName::mode, ModeValue::step);

    QString sNode = nodeToString(node);

    if (sNode.isEmpty() == false) {

    cmd.insert(sxPropName::value, sNode);

    if (connector->sendRequest(cmd, m_devAddress, network::UdpTargetPort, result) == false)
    return false;

    if (result.contains(sxPropName::error))
    return false;

    }

    if (node.hasChildNodes()) {

    QDomNode child = node.firstChild();

    while (child.isNull() == false) {

    sendNode(child);
    child = child.nextSibling();
    }

    cmd.insert(sxPropName::value, QString("</%1>").arg(node.nodeName()));

    if (connector->sendRequest(cmd, m_devAddress, network::UdpTargetPort, result) == false)
    return false;

    if (result.contains(sxPropName::error))
    return false;
    }

    return true;
    }@
    Second is nodeToString method which converts node to string:
    @QString ConfigurationDialog::nodeToString(const QDomNode & node) {

    QString sNode;

    QXmlStreamWriter stream(&sNode);
    stream.setAutoFormatting(false);

    QDomElement elem = node.toElement();
    stream.writeStartElement(elem.tagName());

    QDomNamedNodeMap attrs = elem.attributes();
    int cnt = attrs.count();

    for (int i = 0; i < cnt; i++) {

    QDomNode attrNode = attrs.item(i);

    if (attrNode.isNull())
    continue;

    QString attrValue;
    QXmlStreamWriter charWriter(&attrValue);
    charWriter.writeCharacters(attrNode.nodeValue());

    stream.writeAttribute(attrNode.nodeName(), attrValue);
    }

    if(node.hasChildNodes())
    sNode += ">";
    else
    stream.writeEndElement();

    return sNode;
    }@
    In receiving side I receve all the data and write it to file, and then make QDomDocument and call set content:
    @
    QTemporaryFile * m_tempFile = new QTemporaryFile();

    if (m_tempFile->isOpen())
    m_tempFile->close();

    m_tempFile->remove();
    m_tempFile->open();
    @
    ...
    @
    QString block = cmd.valueS(sxPropName::value);
    QTextStream outStrem(m_tempFile);
    outStrem <<block;
    @
    ...
    @
    m_tempFile->close();
    QDomDocument domDoc;
    QString error;
    int line, column;

    if (domDoc.setContent(m_file, &error, &line, &column) == false) {
    sError = QString("%1 line = %2 column = %3").arg(error).arg(line).arg(column);
    qDebug() << sError;
    return false;
    }
    m_file->close();
    @

    And after all this I've got filled QDomDocument. But some of it's attrobutes when in value I have "<" or ">" or "/" charecters shown like "&rb". How can I convert it to normal string when show somewhere ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.