Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. XML special charecters reading problem
Forum Updated to NodeBB v4.3 + New Features

XML special charecters reading problem

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 685 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anticross
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved